Close source zips after target zip is written. --HG-- branch : HEAD
diff --git a/src/zipmerge.c b/src/zipmerge.c index a842400..03af58a 100644 --- a/src/zipmerge.c +++ b/src/zipmerge.c
@@ -1,6 +1,6 @@ /* zipmerge.c -- merge zip archives - Copyright (C) 2004-2007 Dieter Baron and Thomas Klausner + Copyright (C) 2004-2008 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at <libzip@nih.at> @@ -70,7 +70,7 @@ Report bugs to <libizp@nih.at>.\n"; char version_string[] = PROGRAM " (" PACKAGE " " VERSION ")\n\ -Copyright (C) 2007 Dieter Baron and Thomas Klausner\n\ +Copyright (C) 2008 Dieter Baron and Thomas Klausner\n\ " PACKAGE " comes with ABSOLUTELY NO WARRANTY, to the extent permitted by law.\n"; #define OPTIONS "hVDiIsS" @@ -85,7 +85,7 @@ static int confirm_replace(struct zip *, const char *, int, struct zip *, const char *, int); -static int merge_zip(struct zip *za, const char *, const char *); +static int merge_zip(struct zip *za, const char *, const char *, struct zip **); @@ -93,7 +93,8 @@ main(int argc, char *argv[]) { struct zip *za; - int c, err; + struct zip **zs; + int c, err, i; char errstr[1024], *tname; prg = argv[0]; @@ -142,6 +143,12 @@ } tname = argv[optind++]; + + if ((zs=malloc(sizeof(zs[0])*(argc-optind))) == NULL) { + fprintf(stderr, "%s: out of memory\n", prg); + exit(1); + } + if ((za=zip_open(tname, ZIP_CREATE, &err)) == NULL) { zip_error_to_str(errstr, sizeof(errstr), err, errno); fprintf(stderr, "%s: cannot open zip archive `%s': %s\n", @@ -149,8 +156,8 @@ exit(1); } - while (optind<argc) { - if (merge_zip(za, tname, argv[optind++]) < 0) + for (i=0; i<argc-optind; i++) { + if (merge_zip(za, tname, argv[optind+i], zs+i) < 0) exit(1); } @@ -160,6 +167,9 @@ exit(1); } + for (i=0; i<argc-optind; i++) + zip_close(zs[i]); + exit(0); } @@ -216,7 +226,8 @@ static int -merge_zip(struct zip *za, const char *tname, const char *sname) +merge_zip(struct zip *za, const char *tname, const char *sname, + struct zip **zsp) { struct zip *zs; struct zip_source *source; @@ -275,6 +286,6 @@ } } - zip_close(zs); + *zsp = zs; return 0; }