From 22f72faa03ef44daed5c127023fb3c7b6ebf6fed Mon Sep 17 00:00:00 2001 From: yifang Date: Thu, 17 Feb 2022 20:08:20 +0800 Subject: [PATCH] optimize:fix resource leak Fixes #20 --- dictzip.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dictzip.c b/dictzip.c index fd362239..1ac3c62d 100644 --- a/dictzip.c +++ b/dictzip.c @@ -349,11 +349,13 @@ static enum DZ_ERRORS dict_read_header( const char *filename, } header->chunks = xmalloc( sizeof( header->chunks[0] ) * header->chunkCount ); - if( header->chunks == 0 ) { - return DZ_ERR_NOMEMORY; - } + if( header->chunks == 0 ) + { + fclose( str ); + return DZ_ERR_NOMEMORY; + } - for (i = 0; i < header->chunkCount; i++) { + for (i = 0; i < header->chunkCount; i++) { header->chunks[i] = getc( str ) << 0; header->chunks[i] |= getc( str ) << 8; }