Commit f49d8571 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Clean up and avoid leak in sap decompression

parent 6154f386
...@@ -1208,13 +1208,11 @@ static int InitSocket( services_discovery_t *p_sd, const char *psz_address, ...@@ -1208,13 +1208,11 @@ static int InitSocket( services_discovery_t *p_sd, const char *psz_address,
static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i_len ) static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i_len )
{ {
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
int i_result, i_dstsize, n; int i_result, i_dstsize, n = 0;
unsigned char *psz_dst; unsigned char *psz_dst = NULL;
z_stream d_stream; z_stream d_stream;
d_stream.zalloc = (alloc_func)0; memset (&d_stream, 0, sizeof (d_stream));
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
i_result = inflateInit(&d_stream); i_result = inflateInit(&d_stream);
if( i_result != Z_OK ) if( i_result != Z_OK )
...@@ -1222,9 +1220,6 @@ static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i ...@@ -1222,9 +1220,6 @@ static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i
d_stream.next_in = (Bytef *)psz_src; d_stream.next_in = (Bytef *)psz_src;
d_stream.avail_in = i_len; d_stream.avail_in = i_len;
n = 0;
psz_dst = NULL;
do do
{ {
...@@ -1235,8 +1230,11 @@ static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i ...@@ -1235,8 +1230,11 @@ static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i
i_result = inflate(&d_stream, Z_NO_FLUSH); i_result = inflate(&d_stream, Z_NO_FLUSH);
if( ( i_result != Z_OK ) && ( i_result != Z_STREAM_END ) ) if( ( i_result != Z_OK ) && ( i_result != Z_STREAM_END ) )
{
inflateEnd( &d_stream );
return( -1 ); return( -1 );
} }
}
while( ( d_stream.avail_out == 0 ) && ( d_stream.avail_in != 0 ) && while( ( d_stream.avail_out == 0 ) && ( d_stream.avail_in != 0 ) &&
( i_result != Z_STREAM_END ) ); ( i_result != Z_STREAM_END ) );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment