zip-reader.c: Fix memory leak 20130308030505/pspp
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:46:27 +0000 (21:46 +0100)
src/libpspp/zip-reader.c

index 985b0a9027723180f6362d430ad66e9b8f49c045..7c1e342aa76e51bb513afa1e72cf01d9bf41e7d0 100644 (file)
@@ -382,7 +382,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;
@@ -396,7 +396,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
@@ -450,8 +453,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;