Skip to content

Fix memory leak in minizip's zipOpen3 function - #1291

Open
amarkowski999 wants to merge 1 commit into
madler:developfrom
amarkowski999:fixleak
Open

Fix memory leak in minizip's zipOpen3 function#1291
amarkowski999 wants to merge 1 commit into
madler:developfrom
amarkowski999:fixleak

Conversation

@amarkowski999

Copy link
Copy Markdown

Summary

When zipOpen3() is called with APPEND_STATUS_ADDINZIP and LoadCentralDirectoryRecord() fails after partially reading the central directory, the error path leaks the datablock list and the file stream. Fixes #1223.

Root Cause

The zipOpen3() error path freed ziinit.globalcomment and zi, but never called free_linkedlist(&ziinit.central_dir). The filestream was also only closed on LoadCentralDirectoryRecord()'s early-return path, not on its final error return, so it leaked on the later seek/read failures.

Fix

  • LoadCentralDirectoryRecord(): close the filestream on its final error return, matching the existing early-error handling.
  • zipOpen3(): call free_linkedlist(&(ziinit.central_dir)) on the error path.

Verification

ASan before:

=================================================================
==113671==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4112 byte(s) in 1 object(s) allocated from:
    #1 0x... in allocate_new_datablock zip.c:210
    #2 0x... in add_data_in_datablock zip.c:248
    #3 0x... in LoadCentralDirectoryRecord zip.c:1046
    #4 0x... in zipOpen3 zip.c:1113
SUMMARY: AddressSanitizer: 4112 byte(s) leaked in 1 allocation(s).

After: no leak, and the leaked file descriptor count returns to baseline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible memory leak

1 participant