summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2019-08-22 07:51:13 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-08-30 09:26:06 +0200
commit1a97b56180112cd64c6c37688cf2060d01c6402d (patch)
tree36b26dd362269f55948a14eea0a88e2d6a1a3833
parent3d78b283f252c6774842214c22efb930d3379f3a (diff)
downloadbarebox-1a97b56180112cd64c6c37688cf2060d01c6402d.tar.gz
barebox-1a97b56180112cd64c6c37688cf2060d01c6402d.tar.xz
gui: png_lode: fix freeing of uninitialized pointer
If either calloc or png_uncompress_init fails, free(png) will free the uninitialized png pointer. Avoid this and while at it postpone the img allocation till after the early exit. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--lib/gui/png_lode.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/gui/png_lode.c b/lib/gui/png_lode.c
index 477704d976..e30db0f853 100644
--- a/lib/gui/png_lode.c
+++ b/lib/gui/png_lode.c
@@ -46,15 +46,16 @@ struct image *png_open(char *inbuf, int insize)
LodePNGState state;
int ret;
unsigned error;
- struct image *img = calloc(1, sizeof(struct image));
- unsigned char *png;
-
- if (!img)
- return ERR_PTR(-ENOMEM);
+ struct image *img;
+ unsigned char *png = NULL;
ret = png_uncompress_init();
if (ret)
- goto err;
+ return ERR_PTR(ret);
+
+ img = calloc(1, sizeof(struct image));
+ if (!img)
+ return ERR_PTR(-ENOMEM);
lodepng_state_init(&state);