Move zlib_stream_free to file_archive_zlib.c

This commit is contained in:
twinaphex 2016-01-24 20:01:35 +01:00
parent 9a23d95846
commit 064c5ffc3a
5 changed files with 15 additions and 14 deletions

View File

@ -434,13 +434,6 @@ bool file_archive_inflate_init(void *data)
return true;
}
void zlib_stream_free(void *data)
{
z_stream *ret = (z_stream*)data;
if (ret)
inflateEnd(ret);
}
void zlib_stream_deflate_free(void *data)
{
z_stream *ret = (z_stream*)data;
@ -487,7 +480,7 @@ bool file_archive_inflate_data_to_file_init(
error:
if (handle->stream)
zlib_stream_free(handle->stream);
handle->backend->stream_free(handle->stream);
free(handle->stream);
if (handle->data)
free(handle->data);
@ -564,7 +557,7 @@ int file_archive_inflate_data_to_file(
{
if (handle)
{
zlib_stream_free(handle->stream);
handle->backend->stream_free(handle->stream);
free(handle->stream);
}

View File

@ -31,7 +31,15 @@ static void *zlib_stream_new(void)
return (z_stream*)calloc(1, sizeof(z_stream));
}
static void zlib_stream_free(void *data)
{
z_stream *ret = (z_stream*)data;
if (ret)
inflateEnd(ret);
}
const struct zlib_file_backend zlib_backend = {
zlib_stream_new,
zlib_stream_free,
"zlib"
};

View File

@ -714,7 +714,7 @@ static int rpng_load_image_argb_process_inflate_init(rpng_t *rpng,
return 0;
end:
zlib_stream_free(rpng->process.stream);
rpng->process.stream_backend->stream_free(rpng->process.stream);
*width = rpng->ihdr.width;
*height = rpng->ihdr.height;
@ -741,7 +741,7 @@ end:
return 1;
error:
zlib_stream_free(rpng->process.stream);
rpng->process.stream_backend->stream_free(rpng->process.stream);
false_end:
rpng->process.inflate_initialized = false;
@ -985,7 +985,7 @@ void rpng_nbio_load_image_free(rpng_t *rpng)
free(rpng->process.inflate_buf);
if (rpng->process.stream)
{
zlib_stream_free(rpng->process.stream);
rpng->process.stream_backend->stream_free(rpng->process.stream);
free(rpng->process.stream);
}

View File

@ -364,7 +364,7 @@ end:
free(avg_filtered);
free(paeth_filtered);
zlib_stream_free(stream);
stream_backend->stream_free(stream);
return ret;
}

View File

@ -40,6 +40,7 @@ enum zlib_transfer_type
struct zlib_file_backend
{
void *(*stream_new)(void);
void (*stream_free)(void *);
const char *ident;
};
@ -155,7 +156,6 @@ bool file_archive_perform_mode(const char *name, const char *valid_exts,
struct string_list *compressed_file_list_new(const char *filename,
const char* ext);
void zlib_stream_free(void *data);
void zlib_deflate_init(void *data, int level);