From 6b4936ade4e53719185d1e936939b1afe10442aa Mon Sep 17 00:00:00 2001 From: Xiao Yi Fang Date: Sat, 10 Aug 2024 13:41:23 +0800 Subject: [PATCH] fix: close file when return error --- src/dictzip.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/dictzip.c b/src/dictzip.c index 51b26586..7615c873 100644 --- a/src/dictzip.c +++ b/src/dictzip.c @@ -416,8 +416,9 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header if ( ftell( str ) != header->headerLength + 1 ) { err_internal( __func__, "File position (%lu) != header length + 1 (%d)\n", ftell( str ), header->headerLength + 1 ); fclose( str ); - if ( header->chunks ) + if ( header->chunks ) { free( header->chunks ); + } return DZ_ERR_INVALID_FORMAT; } @@ -435,8 +436,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header /* Compute offsets */ header->offsets = xmalloc( sizeof( header->offsets[ 0 ] ) * header->chunkCount ); if ( header->offsets == 0 ) { - if ( header->chunks ) + if ( header->chunks ) { free( header->chunks ); + } + fclose( str ); return DZ_ERR_NOMEMORY; }