From: Jason Garrett-Glaser Date: Mon, 6 Dec 2010 20:00:13 +0000 (-0800) Subject: Fix file handle leak in libx264 on error X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=b2a6aa433e9b9e1303869fcdb9b9c92b30795f85;p=x264.git Fix file handle leak in libx264 on error --- diff --git a/common/common.c b/common/common.c index 1845e3bc..951e326a 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; } /****************************************************************************