Skip to content

ext/curl: Fix mem leak when duphandle fails in curl_clone_obj - #22899

Closed
Sjord wants to merge 1 commit into
php:PHP-8.4from
Sjord:curl-clone-fail-leak-8.4
Closed

ext/curl: Fix mem leak when duphandle fails in curl_clone_obj#22899
Sjord wants to merge 1 commit into
php:PHP-8.4from
Sjord:curl-clone-fail-leak-8.4

Conversation

@Sjord

@Sjord Sjord commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Move init_curl_handle so that we don't leak memory if curl_easy_duphandle fails within curl_clone_obj.

init_curl_handle allocates things, and curl_free_obj frees that again. But curl_free_obj does nothing if ch->cp is not set. In curl_clone_obj, do the allocation only once we have a valid cp, so that curl_free_obj actually deallocates the memory again. If curl_easy_duphandle fails we have not allocated anything and nothing is cleaned up.

Same as #22894, but for PHP 8.4.

@devnexen

Copy link
Copy Markdown
Member

nit: please prefix commit title with ext/curl:

@LamentXU123 LamentXU123 changed the title Fix mem leak when duphandle fails in curl_clone_obj ext/curl: Fix mem leak when duphandle fails in curl_clone_obj Jul 27, 2026
@LamentXU123

Copy link
Copy Markdown
Member

This is still targeting master @Sjord

Move init_curl_handle so that we don't leak memory if
curl_easy_duphandle fails within curl_clone_obj.

init_curl_handle allocates things, and curl_free_obj frees that again.
But curl_free_obj does nothing if ch->cp is not set. In curl_clone_obj,
do the allocation only once we have a valid cp, so that curl_free_obj
actually deallocates the memory again. If curl_easy_duphandle
fails we have not allocated anything and nothing is cleaned up.
@Sjord
Sjord force-pushed the curl-clone-fail-leak-8.4 branch from 899f57d to 07f468f Compare July 27, 2026 11:13
@Sjord
Sjord changed the base branch from master to PHP-8.4 July 27, 2026 11:13
@Sjord

Sjord commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, I put ext/curl: in the commit message and pointed this to PHP-8.4.

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you. I will take care of merging. Now let's close #22894 as superseded.

LamentXU123 added a commit that referenced this pull request Jul 27, 2026
* PHP-8.5:
  ext/curl: fix mem leak when duphandle fails in curl_clone_obj (#22899)
pull Bot pushed a commit to Mattlk13/php-src that referenced this pull request Jul 27, 2026
* PHP-8.4:
  ext/curl: fix mem leak when duphandle fails in curl_clone_obj (php#22899)
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.

4 participants