summaryrefslogtreecommitdiff
path: root/source3/lib/netapi
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2021-12-10 14:56:08 +0100
committerJeremy Allison <jra@samba.org>2021-12-15 19:32:30 +0000
commit9bd0fbf5e8d2e4cf65d5d26311a8b510eef3eba5 (patch)
tree716b078374ac9a72a24c9c7739069972b0591d4c /source3/lib/netapi
parentc8c3c547646c2f91c63b5a195476d5bed88ae2a1 (diff)
downloadsamba-9bd0fbf5e8d2e4cf65d5d26311a8b510eef3eba5.tar.gz
s3:lib: Fix memory leak in netapi examples
Found by covscan. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/lib/netapi')
-rw-r--r--source3/lib/netapi/examples/common.c8
1 files changed, 6 insertions, 2 deletions
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;
}