From 7d88bdd43baa63b86953eba474047837f1561d35 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Mon, 11 Jan 2016 17:54:17 +0100 Subject: [PATCH] [g2clib] Fix memory leaks --- src/plugins/weatherdata/gfs/g2clib/comunpack.c | 6 ++++++ src/plugins/weatherdata/gfs/g2clib/pngunpack.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/plugins/weatherdata/gfs/g2clib/comunpack.c b/src/plugins/weatherdata/gfs/g2clib/comunpack.c index 1a0b0e009..a98e95a3e 100644 --- a/src/plugins/weatherdata/gfs/g2clib/comunpack.c +++ b/src/plugins/weatherdata/gfs/g2clib/comunpack.c @@ -201,9 +201,15 @@ int comunpack(unsigned char *cpack,g2int lensec,g2int idrsnum,g2int *idrstmpl,g2 totLen += glen[j]; } if (totLen != ndpts) { + free(ifld); + free(gref); + free(gwidth); return 1; } if (totBit / 8. > lensec) { + free(ifld); + free(gref); + free(gwidth); return 1; } // diff --git a/src/plugins/weatherdata/gfs/g2clib/pngunpack.c b/src/plugins/weatherdata/gfs/g2clib/pngunpack.c index 6f269af2b..52cbce6fc 100644 --- a/src/plugins/weatherdata/gfs/g2clib/pngunpack.c +++ b/src/plugins/weatherdata/gfs/g2clib/pngunpack.c @@ -58,6 +58,8 @@ g2int pngunpack(unsigned char *cpack,g2int len,g2int *idrstmpl,g2int ndpts, ctemp=(unsigned char *)calloc(ndpts*4,1); if ( ifld == 0 || ctemp == 0) { fprintf(stderr,"Could not allocate space in jpcunpack.\n Data field NOT upacked.\n"); + if ( ctemp != 0 ) free(ctemp); + if ( ifld != 0 ) free(ifld); return(1); } dec_png(cpack,&width,&height,ctemp);