tools: Fix memory and descriptor leak
PATCH 1/1 tools: Fix memory and descriptor leak
From: Maks Mishin <[email protected]>
Signed-off-by Maks Mishin <[email protected]>
Signed-off-by Anton Moryakov <[email protected]>
--- tools/zynqmpbif.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tools/zynqmpbif.c +9 -5
@@ -205,7 +205,7 @@ static const struct bif_flags bif_flags[] = {static char *read_full_file (const char *filename,size_t *size) { -char *buf, *bufp; +char *buf =NULL , *bufp;struct stat sbuf;int len =0 , r, fd;
@@ -214,24 +214,28 @@ static char *read_full_file(const char *filename, size_t *size)return NULL ;if (fstat (fd, &sbuf) <0 ) -return NULL ; + goto out;if (size) *size = sbuf.st_size; buf =malloc (sbuf.st_size);if (!buf) -return NULL ; + goto out; bufp = buf;while (len < sbuf.st_size) { r =read (fd, bufp, sbuf.st_size - len); -if (r <0 ) -return NULL ; +if (r <0 ) { +free (buf); + buf =NULL ; + goto out; + } len += r; bufp += r; } +out:close (fd);return buf;
Signature · 1 line
2.30.2