summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-06 19:59:50 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-06 21:23:26 +0200
commit5e2aca267883a03dae8193eda9328a48b187fe84 (patch)
treef3c20ca4f242c3acd672adbe20d010e3a2763853
parent6b2b9d303e61599d566a70b6e3100b9afe400d4b (diff)
downloadapk-tools-5e2aca267883a03dae8193eda9328a48b187fe84.tar.gz
apk-tools-5e2aca267883a03dae8193eda9328a48b187fe84.tar.bz2
apk-tools-5e2aca267883a03dae8193eda9328a48b187fe84.tar.xz
apk-tools-5e2aca267883a03dae8193eda9328a48b187fe84.zip
io: fix some memory leaks
-rw-r--r--src/apk_io.h2
-rw-r--r--src/archive.c9
-rw-r--r--src/gunzip.c6
-rw-r--r--src/io.c2
4 files changed, 15 insertions, 4 deletions
diff --git a/src/apk_io.h b/src/apk_io.h
index 833257d..5ac6d83 100644
--- a/src/apk_io.h
+++ b/src/apk_io.h
@@ -43,7 +43,7 @@ struct apk_ostream {
void (*close)(void *stream);
};
-struct apk_istream *apk_bstream_gunzip(struct apk_bstream *);
+struct apk_istream *apk_bstream_gunzip(struct apk_bstream *, int);
struct apk_ostream *apk_ostream_gzip(struct apk_ostream *);
struct apk_istream *apk_istream_from_fd(int fd);
diff --git a/src/archive.c b/src/archive.c
index 0cb575b..7e78659 100644
--- a/src/archive.c
+++ b/src/archive.c
@@ -179,7 +179,14 @@ int apk_parse_tar(struct apk_istream *is, apk_archive_entry_parser parser,
int apk_parse_tar_gz(struct apk_bstream *bs, apk_archive_entry_parser parser,
void *ctx)
{
- return apk_parse_tar(apk_bstream_gunzip(bs), parser, ctx);
+ struct apk_istream *is;
+ int rc;
+
+ is = apk_bstream_gunzip(bs, FALSE);
+ rc = apk_parse_tar(is, parser, ctx);
+ is->close(is);
+
+ return rc;
}
int apk_archive_entry_extract(const struct apk_file_info *ae,
diff --git a/src/gunzip.c b/src/gunzip.c
index 1d641ed..55c9e66 100644
--- a/src/gunzip.c
+++ b/src/gunzip.c
@@ -22,6 +22,7 @@ struct apk_gzip_istream {
struct apk_bstream *bs;
z_stream zs;
int z_err;
+ int autoclose;
};
static size_t gz_read(void *stream, void *ptr, size_t size)
@@ -64,10 +65,12 @@ static void gz_close(void *stream)
container_of(stream, struct apk_gzip_istream, is);
inflateEnd(&gis->zs);
+ if (gis->autoclose)
+ gis->bs->close(gis->bs, NULL, NULL);
free(gis);
}
-struct apk_istream *apk_bstream_gunzip(struct apk_bstream *bs)
+struct apk_istream *apk_bstream_gunzip(struct apk_bstream *bs, int autoclose)
{
struct apk_gzip_istream *gis;
@@ -83,6 +86,7 @@ struct apk_istream *apk_bstream_gunzip(struct apk_bstream *bs)
.is.close = gz_close,
.bs = bs,
.z_err = 0,
+ .autoclose = autoclose,
};
if (inflateInit2(&gis->zs, 15+32) != Z_OK) {
diff --git a/src/io.c b/src/io.c
index 78452a9..2c94886 100644
--- a/src/io.c
+++ b/src/io.c
@@ -389,7 +389,7 @@ int apk_file_get_info(const char *filename, struct apk_file_info *fi)
struct apk_istream *apk_istream_from_file_gz(const char *file)
{
- return apk_bstream_gunzip(apk_bstream_from_file(file));
+ return apk_bstream_gunzip(apk_bstream_from_file(file), TRUE);
}
struct apk_fd_ostream {