I'm still seeing leaks here. So just stop allocating for these variables.
[oweals/opkg-lede.git] / libbb / unarchive.c
index 53fa89980b48d6f268ad591d3a667c43ceede247..bd10ad92d6cdd42d2bb42c711af8680805aa5280 100644 (file)
@@ -729,7 +729,7 @@ void free_header_tar(file_header_t *tar_entry)
 char *deb_extract(const char *package_filename, FILE *out_stream, 
                  const int extract_function, const char *prefix, const char *filename)
 {
-       FILE *deb_stream;
+       FILE *deb_stream = NULL;
        FILE *uncompressed_stream = NULL;
        file_header_t *ar_header = NULL;
        char **file_list = NULL;
@@ -740,15 +740,15 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
 
        if (filename != NULL) {
                file_list = xmalloc(sizeof(char *) * 2);
-               file_list[0] = xstrdup(filename);
+               file_list[0] = filename;
                file_list[1] = NULL;
        }
        
        if (extract_function & extract_control_tar_gz) {
-               ared_file = xstrdup("control.tar.gz");
+               ared_file = "control.tar.gz";
        }
        else if (extract_function & extract_data_tar_gz) {              
-               ared_file = xstrdup("data.tar.gz");
+               ared_file = "data.tar.gz";
        } else {
                 fprintf(stderr, "no file specified to extract -- extract_function=%x\n", extract_function);
                goto cleanup;
@@ -784,9 +784,7 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
                        free (ar_header);
                }
                gz_close(gunzip_pid);
-               fclose(deb_stream);
                fclose(uncompressed_stream);
-               free(ared_file);
                goto cleanup;
        } else if (strncmp(ar_magic, "\037\213", 2) == 0) {
                /* it's a gz file, let's assume it's an opkg */
@@ -832,8 +830,6 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
                }
                gz_close(unzipped_opkg_pid);
                fclose(unzipped_opkg_stream);
-               fclose(deb_stream);
-               free(ared_file);
                 /*fprintf(stderr, __FUNCTION__ ":%d: done\n", __LINE__);*/
                goto cleanup;
        } else {
@@ -841,10 +837,10 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
        }
 
 cleanup:
-       if (file_list) {
-               free(file_list[0]);
+       if (deb_stream)
+               fclose(deb_stream);
+       if (file_list)
                free(file_list);
-       }
 
        return output_buffer;
 }