]> git.sesse.net Git - vlc/commitdiff
Clean up and avoid leak in sap decompression
authorRémi Denis-Courmont <rem@videolan.org>
Tue, 14 Nov 2006 16:53:51 +0000 (16:53 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Tue, 14 Nov 2006 16:53:51 +0000 (16:53 +0000)
modules/services_discovery/sap.c

index aec836f71130c7723d15367b1c6288db2f469724..1c05f29f4a962f1a0c7366641b28aba817133a73 100644 (file)
@@ -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 )
 {
 #ifdef HAVE_ZLIB_H
-    int i_result, i_dstsize, n;
-    unsigned char *psz_dst;
+    int i_result, i_dstsize, n = 0;
+    unsigned char *psz_dst = NULL;
     z_stream d_stream;
 
-    d_stream.zalloc = (alloc_func)0;
-    d_stream.zfree = (free_func)0;
-    d_stream.opaque = (voidpf)0;
+    memset (&d_stream, 0, sizeof (d_stream));
 
     i_result = inflateInit(&d_stream);
     if( i_result != Z_OK )
@@ -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.avail_in = i_len;
-    n = 0;
-
-    psz_dst = NULL;
 
     do
     {
@@ -1235,7 +1230,10 @@ static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i
 
         i_result = inflate(&d_stream, Z_NO_FLUSH);
         if( ( i_result != Z_OK ) && ( i_result != Z_STREAM_END ) )
+        {
+            inflateEnd( &d_stream );
             return( -1 );
+        }
     }
     while( ( d_stream.avail_out == 0 ) && ( d_stream.avail_in != 0 ) &&
            ( i_result != Z_STREAM_END ) );