Free memory in error paths.
[oweals/opkg-lede.git] / libbb / unzip.c
index 08c17d4a2927877a7ad10f85b2791eafd8eda4e7..058aa07535539719180b3c3b28b1394f4116a25f 100644 (file)
@@ -113,7 +113,7 @@ static void make_crc_table()
 
        /* initial shift register value */
        crc = 0xffffffffL;      
-       crc_table = (unsigned long *) malloc(256 * sizeof(unsigned long));
+       crc_table = (unsigned long *) xmalloc(256 * sizeof(unsigned long));
 
        /* Make exclusive-or pattern from polynomial (0xedb88320) */
        for (i = 0; i < sizeof(p)/sizeof(int); i++)
@@ -639,8 +639,11 @@ static int inflate_block(int *e)
                        }
 
                        /* decompress until an end-of-block code */
-                       if (inflate_codes(tl, td, bl, bd))
+                       if (inflate_codes(tl, td, bl, bd)) {
+                               huft_free(tl);
+                               huft_free(td);
                                return 1;
+                       }
 
                        /* free the decoding tables, return */
                        huft_free(tl);
@@ -816,8 +819,11 @@ static int inflate_block(int *e)
                        }
 
                        /* decompress until an end-of-block code */
-                       if (inflate_codes(tl, td, bl, bd))
+                       if (inflate_codes(tl, td, bl, bd)) {
+                               huft_free(tl);
+                               huft_free(td);
                                return 1;
+                       }
 
                        /* free the decoding tables, return */
                        huft_free(tl);
@@ -1005,19 +1011,3 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
 
        return exit_code;
 }
-
-/*
- * This needs access to global variables wondow and crc_table, so its not in its own file.
- */
-extern void gz_close(int gunzip_pid)
-{
-       if (kill(gunzip_pid, SIGTERM) == -1) {
-               error_msg_and_die("***  Couldnt kill old gunzip process *** aborting");
-       }
-
-       if (waitpid(gunzip_pid, NULL, 0) == -1) {
-               printf("Couldnt wait ?");
-       }
-               free(window);
-               free(crc_table);
-}