From e8d90fe7525c177f0c28f6843f2a25da2e6e5045 Mon Sep 17 00:00:00 2001
From: jmoellers <josef.moellers@suse.com>
Date: Fri, 7 Sep 2018 11:49:28 +0200
Subject: [PATCH 2/3] Avoid memory leak from __zzip_parse_root_directory().

(cherry picked from commit d2e5d5c53212e54a97ad64b793a4389193fec687)
https://github.com/gdraheim/zziplib/commit/d2e5d5c53212e54a97ad64b793a4389193fec687
Signed-off-by: Yufa Fang <fangyufa1@huawei.com>
---
 zzip/zip.c | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/zzip/zip.c b/zzip/zip.c
index 8318463..79fd9ad 100644
--- a/zzip/zip.c
+++ b/zzip/zip.c
@@ -584,34 +584,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 ------------------------- */
-- 
2.19.1

