From b2a6aa433e9b9e1303869fcdb9b9c92b30795f85 Mon Sep 17 00:00:00 2001 From: Jason Garrett-Glaser Date: Mon, 6 Dec 2010 12:00:13 -0800 Subject: [PATCH] Fix file handle leak in libx264 on error --- common/common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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; } /**************************************************************************** -- 2.47.3