]> granicus.if.org Git - zziplib/commitdiff
Avoid memory leak from __zzip_parse_root_directory().
authorjmoellers <josef.moellers@suse.com>
Fri, 7 Sep 2018 09:49:28 +0000 (11:49 +0200)
committerjmoellers <josef.moellers@suse.com>
Fri, 7 Sep 2018 09:49:28 +0000 (11:49 +0200)
zzip/zip.c

index a6852802f87e9b2dc737fda2e7d2a858fb2bb4c0..51a1a4d93a60d746db454cbc428f9f1e7c68e7b2 100644 (file)
@@ -587,34 +587,13 @@ __zzip_parse_root_directory(int fd,
        {
            /* If it is not assigned to *hdr_return, it will never be free()'d */
            free(hdr0);
-           /* Make sure we don't free it again in case of error */
-           hdr0 = NULL;
        }
     }                           /* else zero (sane) entries */
 #  ifndef ZZIP_ALLOW_MODULO_ENTRIES
-    if (entries != zz_entries)
-    {
-       /* If it was assigned to *hdr_return, undo assignment */
-       if (p_reclen && hdr_return)
-           *hdr_return = NULL;
-       /* Free it, if it was not already free()'d */
-       if (hdr0 != NULL)
-           free(hdr0);
-       return ZZIP_CORRUPTED;
-    }
+    return (entries != zz_entries) ? ZZIP_CORRUPTED : 0;
 #  else
-    if (((entries & (unsigned)0xFFFF) != zz_entries)
-    {
-       /* If it was assigned to *hdr_return, undo assignment */
-       if (p_reclen && hdr_return)
-           *hdr_return = NULL;
-       /* Free it, if it was not already free()'d */
-       if (hdr0 != NULL)
-           free(hdr0);
-       return ZZIP_CORRUPTED;
-    }
+    return ((entries & (unsigned)0xFFFF) != zz_entries) ? ZZIP_CORRUPTED : 0;
 #  endif
-    return 0;
 }
 
 /* ------------------------- high-level interface ------------------------- */