diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-12-09 21:28:33 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-12-10 20:50:53 -0800 |
commit | fa46fad55550e100c50a3f4208aa953a29cfc3df (patch) | |
tree | 244cdc420dfd1a7bdcf9432aea9106eb7372cdc0 | |
parent | 2cc2b4bf7f370c5c804f4e75228677b2c58f1d7f (diff) |
Stop leaking temporary buffer when realloc fails to enlarge it
Fixes cppcheck error:
[readfile.c:108]: (error) Common realloc mistake: 'cp' nulled
but not freed upon failure
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: wharms <wharms@bfs.de>
-rw-r--r-- | readfile.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -104,9 +104,11 @@ get_data_from_stdin (int *len_return) count += n; /* Here count <= allocated. Prepare for next round. */ if (count + BUFSIZ > allocated) { + char *oldp = cp; allocated = 2 * allocated; cp = realloc (cp, allocated + 1); if (!cp) { + free(oldp); fprintf(stderr, "cannot get memory for message file\n"); return NULL; } |