io: fix some memory leaks
parent
6b2b9d303e
commit
5e2aca2678
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
2
src/io.c
2
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 {
|
||||
|
|
Loading…
Reference in New Issue