summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2014-01-06 11:05:07 +0000
committerMarcus Meissner <marcus@jet.franken.de>2014-01-06 11:05:07 +0000
commitfa60081c2fac8963f44f4cb69109a97e2ea4f808 (patch)
tree0b4ed016cbc6cabe90ea8f09d8ef18cdb16e0a1a
parent6ab75195627bdc7ee6ccca0a64cf8b57ecd0e740 (diff)
downloadlibgphoto2-fa60081c2fac8963f44f4cb69109a97e2ea4f808.tar.gz
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
-rw-r--r--camlibs/ptp2/ptp-pack.c14
1 files 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<n;i++)
(*array)[i]=dtoh32a(&data[offset+(sizeof(uint32_t)*(i+1))]);
- i++;
- }
return n;
}
@@ -290,14 +291,15 @@ ptp_unpack_uint16_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(uint16_t))
return 0;
+ if (!n)
+ return 0;
*array = malloc (n*sizeof(uint16_t));
- while (n>i) {
+ for (i=0;i<n;i++)
(*array)[i]=dtoh16a(&data[offset+(sizeof(uint16_t)*(i+2))]);
- i++;
- }
return n;
}