[x264-devel] commit: Fix file handle leak in libx264 on error (Jason Garrett-Glaser )

git at videolan.org git at videolan.org
Tue Dec 7 09:15:48 CET 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Mon Dec  6 12:00:13 2010 -0800| [b2a6aa433e9b9e1303869fcdb9b9c92b30795f85] | committer: Jason Garrett-Glaser 

Fix file handle leak in libx264 on error

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=b2a6aa433e9b9e1303869fcdb9b9c92b30795f85
---

 common/common.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/common/common.c b/common/common.c
index 1845e3b..951e326 100644
--- a/common/common.c
+++ b/common/common.c
@@ -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;
 }
 
 /****************************************************************************



More information about the x264-devel mailing list