Skip to content

Commit

Permalink
Merge pull request #1723 from xiaoyifang/fix/file-close
Browse files Browse the repository at this point in the history
fix: close file when return error
  • Loading branch information
xiaoyifang authored Aug 10, 2024
2 parents 65ae8f5 + 6b4936a commit 2dcf2a3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/dictzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 2dcf2a3

Please sign in to comment.