Skip to content

Commit

Permalink
configfile: Avoid memory leaks in case of realloc failure (cppcheck w…
Browse files Browse the repository at this point in the history
…arning)

The original patch was written by Bob Relyea for RHEL package, but I tweaked it
a bit to make sure it builds without warnings.

Signed-off-by: Jakub Jelen <[email protected]>
  • Loading branch information
Jakuje authored and LudovicRousseau committed May 30, 2019
1 parent 4369771 commit f759792
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/configfile.l
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,18 @@ int evaluatetoken(char *pcToken)
}
else
{
SerialReader *new_reader_list = NULL;
reader_list_size++;
reader_list = realloc(reader_list, reader_list_size *
new_reader_list = realloc(reader_list, reader_list_size *
sizeof(SerialReader));
if (new_reader_list == NULL)
free(reader_list);
reader_list = new_reader_list;
}
if (reader_list == NULL)
{
tok_error("No Memory");
return 1;
}

/* end marker */
Expand Down

0 comments on commit f759792

Please sign in to comment.