]> granicus.if.org Git - libx264/commitdiff
flv: Fix memory and file handle leaks
authorHenrik Gramner <henrik@gramner.com>
Tue, 23 Jun 2015 22:22:56 +0000 (00:22 +0200)
committerAnton Mitrofanov <BugMaster@narod.ru>
Fri, 24 Jul 2015 21:39:37 +0000 (00:39 +0300)
output/flv.c

index 10b9533247e7d62acaa9409d2c0ffefc9e035128..00a6afca2eb70e4cd7eb1c56ba47bcba2bce934b 100644 (file)
@@ -75,21 +75,29 @@ static int write_header( flv_buffer *c )
 
 static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt )
 {
-    *p_handle = NULL;
     flv_hnd_t *p_flv = calloc( 1, sizeof(flv_hnd_t) );
-    if( !p_flv )
-        return -1;
-
-    p_flv->b_dts_compress = opt->use_dts_compress;
-
-    p_flv->c = flv_create_writer( psz_filename );
-    if( !p_flv->c )
-        return -1;
-
-    CHECK( write_header( p_flv->c ) );
-    *p_handle = p_flv;
+    if( p_flv )
+    {
+        flv_buffer *c = flv_create_writer( psz_filename );
+        if( c )
+        {
+            if( !write_header( c ) )
+            {
+                p_flv->c = c;
+                p_flv->b_dts_compress = opt->use_dts_compress;
+                *p_handle = p_flv;
+                return 0;
+            }
+
+            fclose( c->fp );
+            free( c->data );
+            free( c );
+        }
+        free( p_flv );
+    }
 
-    return 0;
+    *p_handle = NULL;
+    return -1;
 }
 
 static int set_param( hnd_t handle, x264_param_t *p_param )
@@ -326,8 +334,9 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest
     }
 
     fclose( c->fp );
-    free( p_flv );
+    free( c->data );
     free( c );
+    free( p_flv );
 
     return 0;
 }