From: Andreas Schneider Date: Fri, 10 Dec 2021 13:56:08 +0000 (+0100) Subject: s3:lib: Fix memory leak in netapi examples X-Git-Tag: tdb-1.4.6~267 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9bd0fbf5e8d2e4cf65d5d26311a8b510eef3eba5;p=thirdparty%2Fsamba.git s3:lib: Fix memory leak in netapi examples Found by covscan. Signed-off-by: Andreas Schneider Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/netapi/examples/common.c b/source3/lib/netapi/examples/common.c index a1a491e60c2..997144a34e2 100644 --- a/source3/lib/netapi/examples/common.c +++ b/source3/lib/netapi/examples/common.c @@ -126,6 +126,7 @@ char *netapi_read_file(const char *filename, uint32_t *psize) } while (size < maxsize) { + char *tmp = NULL; size_t newbufsize; size_t nread; @@ -136,10 +137,12 @@ char *netapi_read_file(const char *filename, uint32_t *psize) goto fail; /* overflow */ } - p = realloc(p, sizeof(char)*newbufsize); - if (p == NULL) { + tmp = realloc(p, sizeof(char) * newbufsize); + if (tmp == NULL) { + free(p); goto fail; } + p = tmp; nread = fread(p+size, 1, chunk, file); size += nread; @@ -151,6 +154,7 @@ char *netapi_read_file(const char *filename, uint32_t *psize) err = ferror(file); if (err != 0) { + free(p); goto fail; }