zip-reader.c: Fix memory leak
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 7 Mar 2013 20:45:43 +0000 (21:45 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Thu, 7 Mar 2013 20:45:43 +0000 (21:45 +0100)
src/libpspp/zip-reader.c

index a36bd6f25f24d3db7176f403bbea9337017740b1..3f1d277c92ab140e19653e4383a116bdeb86c1d8 100644 (file)
@@ -384,7 +384,7 @@ zip_member_open (struct zip_reader *zr, const char *member)
   uint32_t ucomp_size, comp_size;
   
   uint32_t crc;
-
+  bool new_member = false;
   char *name = NULL;
 
   int i;
@@ -398,7 +398,10 @@ zip_member_open (struct zip_reader *zr, const char *member)
     zm = zr->members[i];
 
     if (zm == NULL)
-      zm = zr->members[i] = zip_header_read_next (zr);
+      {
+       zm = zr->members[i] = zip_header_read_next (zr);
+       new_member = true;
+      }
     if (zm && 0 == strcmp (zm->name, member))
       break;
     else
@@ -452,8 +455,11 @@ zip_member_open (struct zip_reader *zr, const char *member)
   free (name);
 
   zm->bytes_unread = zm->ucomp_size;
+  
+  if ( !new_member)
+    decompressors[zm->compression].finish (zm);
 
-  if ( !  decompressors[zm->compression].init (zm) )
+  if (!decompressors[zm->compression].init (zm) )
     return NULL;
 
   return zm;