Skip to content

ext/zip: memory leak when zip cancel callback bails out.#22177

Open
devnexen wants to merge 2 commits into
php:masterfrom
devnexen:gh22176
Open

ext/zip: memory leak when zip cancel callback bails out.#22177
devnexen wants to merge 2 commits into
php:masterfrom
devnexen:gh22176

Conversation

@devnexen
Copy link
Copy Markdown
Member

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.

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
@devnexen devnexen marked this pull request as ready for review May 29, 2026 06:34
Copy link
Copy Markdown
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in ZipArchive when registerCancelCallback is used with a reference-returning function during shutdown

2 participants