blob: e92746660b22c4c9e7918aea384904de260047ef [file] [log] [blame]
Dieter Baronbbb63691999-07-26 22:04:20 +00001/*
Dieter Baron549ac372003-10-06 22:44:07 +00002 $NiH: zip_free.c,v 1.7 2003/10/06 16:37:41 dillo Exp $
Dieter Baron1c5ffe22002-06-06 09:27:17 +00003
Dieter Baronbbb63691999-07-26 22:04:20 +00004 zip_free.c -- free struct zip
Thomas Klausnerb6632a42003-03-16 10:22:21 +00005 Copyright (C) 1999 Dieter Baron and Thomas Klausner
Dieter Baronbbb63691999-07-26 22:04:20 +00006
Dieter Barondd9afca2003-10-02 14:13:37 +00007 This file is part of libzip, a library to manipulate ZIP archives.
Dieter Baronbbb63691999-07-26 22:04:20 +00008 The authors can be contacted at <nih@giga.or.at>
9
Dieter Barondd9afca2003-10-02 14:13:37 +000010 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions
12 are met:
13 1. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in
17 the documentation and/or other materials provided with the
18 distribution.
19 3. The names of the authors may not be used to endorse or promote
20 products derived from this software without specific prior
21 written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
24 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
27 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Dieter Baronbbb63691999-07-26 22:04:20 +000034*/
35
36
37
Thomas Klausner6f9e01a1999-07-26 02:50:59 +000038#include <stdlib.h>
39#include "zip.h"
40#include "zipint.h"
41
42
43
44/* _zip_free:
45 frees the space allocated to a zipfile struct, and closes the
Dieter Baronadaf98c2003-10-06 16:37:42 +000046 corresponding file. */
Thomas Klausner6f9e01a1999-07-26 02:50:59 +000047
Dieter Baronadaf98c2003-10-06 16:37:42 +000048void
Thomas Klausner6f9e01a1999-07-26 02:50:59 +000049_zip_free(struct zip *zf)
50{
Dieter Baronadaf98c2003-10-06 16:37:42 +000051 int i;
Thomas Klausnerb1b044e1999-07-26 03:59:58 +000052
Thomas Klausner6f9e01a1999-07-26 02:50:59 +000053 if (zf == NULL)
Dieter Baron549ac372003-10-06 22:44:07 +000054 return;
Thomas Klausner6f9e01a1999-07-26 02:50:59 +000055
56 if (zf->zn)
57 free(zf->zn);
58
59 if (zf->zp)
Dieter Baronadaf98c2003-10-06 16:37:42 +000060 fclose(zf->zp);
Thomas Klausner6f9e01a1999-07-26 02:50:59 +000061
62 if (zf->com)
63 free(zf->com);
64
65 if (zf->entry) {
66 for (i=0; i<zf->nentry; i++) {
67 _zip_free_entry(zf->entry+i);
68 }
69 free (zf->entry);
70 }
71
72 for (i=0; i<zf->nfile; i++) {
73 zf->file[i]->flags = ZERR_ZIPCLOSED;
74 zf->file[i]->zf = NULL;
75 zf->file[i]->name = NULL;
76 }
77
78 free(zf->file);
79
80 free(zf);
81
Dieter Baronadaf98c2003-10-06 16:37:42 +000082 return;
Thomas Klausner6f9e01a1999-07-26 02:50:59 +000083}