Skip to content

Commit

Permalink
ensure disk_close to avoid mem-leak #40
Browse files Browse the repository at this point in the history
  • Loading branch information
gdraheim committed Mar 14, 2018
1 parent 0482c92 commit 83a2da5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
57 changes: 30 additions & 27 deletions bins/unzzipcat-mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static FILE* create_fopen(char* name, char* mode, int subdirs)

static int unzzip_cat (int argc, char ** argv, int extract)
{
int done;
int done = 0;
int argn;
ZZIP_MEM_DISK* disk;

Expand All @@ -116,47 +116,50 @@ static int unzzip_cat (int argc, char ** argv, int extract)
FILE* out = stdout;
if (extract) out = create_fopen(name, "wb", 1);
if (! out) {
if (errno != EISDIR) done = EXIT_ERRORS;
if (errno != EISDIR) {
DBG3("can not open output file %i %s", errno, strerror(errno));
done = EXIT_ERRORS;
}
continue;
}
unzzip_mem_disk_cat_file (disk, name, out);
if (extract) fclose(out);
}
return done;
}

if (argc == 3 && !extract)
}
else if (argc == 3 && !extract)
{ /* list from one spec */
ZZIP_MEM_ENTRY* entry = 0;
while ((entry = zzip_mem_disk_findmatch(disk, argv[2], entry, 0, 0)))
{
unzzip_mem_entry_fprint (disk, entry, stdout);
}

return 0;
}

for (argn=1; argn < argc; argn++)
{ /* list only the matching entries - each in order of commandline */
ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
{
char* name = zzip_mem_entry_to_name (entry);
if (! _zzip_fnmatch (argv[argn], name,
_zzip_FNM_NOESCAPE|_zzip_FNM_PATHNAME|_zzip_FNM_PERIOD))
} else {
for (argn=1; argn < argc; argn++)
{ /* list only the matching entries - each in order of commandline */
ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
{
FILE* out = stdout;
if (extract) out = create_fopen(name, "wb", 1);
if (! out) {
if (errno != EISDIR) done = EXIT_ERRORS;
continue;
}
unzzip_mem_disk_cat_file (disk, name, out);
if (extract) fclose(out);
break; /* match loop */
char* name = zzip_mem_entry_to_name (entry);
if (! _zzip_fnmatch (argv[argn], name,
_zzip_FNM_NOESCAPE|_zzip_FNM_PATHNAME|_zzip_FNM_PERIOD))
{
FILE* out = stdout;
if (extract) out = create_fopen(name, "wb", 1);
if (! out) {
if (errno != EISDIR) {
DBG3("can not open output file %i %s", errno, strerror(errno));
done = EXIT_ERRORS;
}
continue;
}
unzzip_mem_disk_cat_file (disk, name, out);
if (extract) fclose(out);
break; /* match loop */
}
}
}
}
zzip_mem_disk_close(disk);
return done;
}

Expand Down
10 changes: 4 additions & 6 deletions bins/unzzipdir-mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ unzzip_list (int argc, char ** argv, int verbose)
printf ("%lli/%lli %s %s\n", csize, usize, defl, name);
}
}
return 0;
}

if (argc == 3)
else if (argc == 3)
{ /* list from one spec */
ZZIP_MEM_ENTRY* entry = 0;
while ((entry = zzip_mem_disk_findmatch(disk, argv[2], entry, 0, 0)))
Expand All @@ -89,9 +87,8 @@ unzzip_list (int argc, char ** argv, int verbose)
printf ("%lli/%lli %s %s\n", csize, usize, defl, name);
}
}
return 0;
}

else
{ /* list only the matching entries - in order of zip directory */
ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
Expand All @@ -118,8 +115,9 @@ unzzip_list (int argc, char ** argv, int verbose)
}
}
}
return 0;
}
zzip_mem_disk_close(disk);
return EXIT_OK;
}

int
Expand Down

0 comments on commit 83a2da5

Please sign in to comment.