From fa60081c2fac8963f44f4cb69109a97e2ea4f808 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Mon, 6 Jan 2014 11:05:07 +0000 Subject: [PATCH] fixed obscure memleak if we do 0 entries git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@14650 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/ptp2/ptp-pack.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/camlibs/ptp2/ptp-pack.c b/camlibs/ptp2/ptp-pack.c index 6cec90ca4..4d138340f 100644 --- a/camlibs/ptp2/ptp-pack.c +++ b/camlibs/ptp2/ptp-pack.c @@ -262,14 +262,15 @@ ptp_unpack_uint32_t_array(PTPParams *params, unsigned char* data, uint16_t offse { uint32_t n, i=0; + *array = NULL; n=dtoh32a(&data[offset]); if (n >= UINT_MAX/sizeof(uint32_t)) return 0; + if (!n) + return 0; *array = malloc (n*sizeof(uint32_t)); - while (n>i) { + for (i=0;i= UINT_MAX/sizeof(uint16_t)) return 0; + if (!n) + return 0; *array = malloc (n*sizeof(uint16_t)); - while (n>i) { + for (i=0;i