Adding a new temporary variable for realloc memory in order to keep the reference to the allocated memory before the function returns.

In case that realloc fails (i.e. OOM), before exiting with "return(1)", the application is still able to free the corresponding allocated memory.

Signed-off-by: Eduardo Sanchez <ledusanchez@gmail.com>
pull/211/merge
Eduardo Sanchez 10 years ago
parent cdf054719c
commit dae1f95371
No known key found for this signature in database
GPG Key ID: ABDB14F4C8174F81

@ -128,15 +128,20 @@ int load_stdin(void)
{
long pos = 0, rlen;
char buf[1024];
char *aux_message = NULL;
mode = MSGMODE_STDIN_FILE;
while(!feof(stdin)){
rlen = fread(buf, 1, 1024, stdin);
message = realloc(message, pos+rlen);
if(!message){
aux_message = realloc(message, pos+rlen);
if(!aux_message){
if(!quiet) fprintf(stderr, "Error: Out of memory.\n");
free(message);
return 1;
} else
{
message = aux_message;
}
memcpy(&(message[pos]), buf, rlen);
pos += rlen;

Loading…
Cancel
Save