ext/zip: memory leak when zip cancel callback bails out.#22177
Open
devnexen wants to merge 2 commits into
Open
ext/zip: memory leak when zip cancel callback bails out.#22177devnexen wants to merge 2 commits into
devnexen wants to merge 2 commits into
Conversation
Fix php#22176 A cancel callback that throws during the implicit zip_close() in the shutdown destructor triggers a zend_bailout that longjmps through libzip, skipping its free(filelist). Wrap the call in zend_try/zend_catch and cancel on bailout so libzip can unwind and clean up. While at it, apply the same guard to the progress callback, which is invoked from libzip the same way and is prone to the identical leak. close phpGH-22177
iluuu1994
requested changes
May 29, 2026
Member
iluuu1994
left a comment
There was a problem hiding this comment.
This looks incomplete. The bailout should resume after the cleanup is complete, or execution will just resume as normal with the VM potentially being in an invalid state. FWIU, the callback will also be called on manual zip close, which can happen during execution, not just shutdown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #22176
A cancel callback that throws during the implicit zip_close() in the shutdown destructor triggers a zend_bailout that longjmps through libzip, skipping its free(filelist). Wrap the call in zend_try/zend_catch and cancel on bailout so libzip can unwind and clean up.
While at it, apply the same guard to the progress callback, which is invoked from libzip the same way and is prone to the identical leak.