]> git.videolan.org Git - x264.git/commitdiff
Fix file handle leak in libx264 on error
authorJason Garrett-Glaser <darkshikari@gmail.com>
Mon, 6 Dec 2010 20:00:13 +0000 (12:00 -0800)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Tue, 7 Dec 2010 02:56:52 +0000 (18:56 -0800)
common/common.c

index 1845e3bc33980941f9f133a56beb9a0e56b8d6a9..951e326aa1a41abb8685d1461a8017f13d4217a2 100644 (file)
@@ -1166,10 +1166,10 @@ char *x264_slurp_file( const char *filename )
     b_error |= ( i_size = ftell( fh ) ) <= 0;
     b_error |= fseek( fh, 0, SEEK_SET ) < 0;
     if( b_error )
-        return NULL;
+        goto error;
     buf = x264_malloc( i_size+2 );
-    if( buf == NULL )
-        return NULL;
+    if( !buf )
+        goto error;
     b_error |= fread( buf, 1, i_size, fh ) != i_size;
     if( buf[i_size-1] != '\n' )
         buf[i_size++] = '\n';
@@ -1181,6 +1181,9 @@ char *x264_slurp_file( const char *filename )
         return NULL;
     }
     return buf;
+error:
+    fclose( fh );
+    return NULL;
 }
 
 /****************************************************************************