[curl] Free pushed handle when CURLMOPT_PUSHFUNCTION denies or throws - #297
Open
iliaal wants to merge 1 commit into
Open
[curl] Free pushed handle when CURLMOPT_PUSHFUNCTION denies or throws#297iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
When the server push callback denies the push (or throws, leaving retval undefined) libcurl destroys the easy handle itself, so the wrapper must not touch ch->cp afterwards; previously the newly created CurlHandle zval was never released, leaking the object and permanently bumping the shared parent clone counter because _php_setup_easy_copy_handlers() had already registered the clone. The per-instance teardown (handler buffers, FCCs, stream refs, postfields/private_data) is factored out of curl_free_obj() into _php_curl_free_instance() and reused for the denied handle, keeping curl destructors owned by the surviving clone counter invariant intact; sibling audit found no other affected call sites.
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.
On CURL_PUSH_DENY or a throw in the CURLMOPT_PUSHFUNCTION callback, libcurl destroys the pushed handle itself, but ext/curl leaves ch->cp stale and never releases the new CurlHandle zval, leaking a wrapper per denied push. _php_setup_easy_copy_handlers() had cloned it from the parent, so the shared clone counter stays permanently bumped and ch->cp dangles. Teardown moves from curl_free_obj() into _php_curl_free_instance(), reused when the callback denies or throws to clear ch->cp, undo the increment, release state and drop the zval. The phpt drives 200 denied pushes, skipping when none arrive.