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

[email protected] (Sjord) Sun, 26 Jul 2026 19:22:37 +0000
Newsgroups php.git-pulls
Message-ID <5ydQo3WVnEoCaLpLPHeJiirn35VYiLV4yBKG07FsHw0@main.internal.php.net>
Pull Request: https://github.com/php/php-src/pull/22894
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.