Skip to content

Commit

Permalink
Minor fix to mz_zip_writer_add_file - moving local header+alignment b…
Browse files Browse the repository at this point in the history
…yte write up before the src file is open to avoid an fclose() leak
  • Loading branch information
[email protected] committed Oct 14, 2013
1 parent 2d8997f commit 54c4c73
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -4440,6 +4440,9 @@ mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name,
if (!mz_zip_get_file_modified_time(pSrc_filename, &dos_time, &dos_date))
return MZ_FALSE;

if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes + sizeof(local_dir_header)))
return MZ_FALSE;

pSrc_file = MZ_FOPEN(pSrc_filename, "rb");
if (!pSrc_file)
return MZ_FALSE;
Expand All @@ -4456,8 +4459,6 @@ mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name,
if (uncomp_size <= 3)
level = 0;

if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes + sizeof(local_dir_header)))
return MZ_FALSE;
local_dir_header_ofs += num_alignment_padding_bytes;
if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); }
cur_archive_file_ofs += num_alignment_padding_bytes + sizeof(local_dir_header);
Expand Down

0 comments on commit 54c4c73

Please sign in to comment.