[GIT-PULLS] [php-src] PR #22899: Fix mem leak when duphandle fails in curl_clone_obj

[email protected] (Sjord) Mon, 27 Jul 2026 09:48:59 +0000
Newsgroups php.git-pulls
Message-ID <[email protected]>
Pull Request: https://github.com/php/php-src/pull/22899
Author: 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.

Same as https://github.com/php/php-src/pull/22894, but for PHP 8.4.