summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-12-09 21:28:33 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-12-10 20:50:53 -0800
commitfa46fad55550e100c50a3f4208aa953a29cfc3df (patch)
tree244cdc420dfd1a7bdcf9432aea9106eb7372cdc0
parent2cc2b4bf7f370c5c804f4e75228677b2c58f1d7f (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.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/readfile.c b/readfile.c
index 9729854..122020f 100644
--- a/readfile.c
+++ b/readfile.c
@@ -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;
}