Skip to content

Commit 3163ac7

Browse files
SjordLamentXU123
authored andcommitted
ext/curl: fix mem leak when duphandle fails in curl_clone_obj (#22899)
Move init_curl_handle() so that memory is not leaked if curl_easy_duphandle() fails within curl_clone_obj(). init_curl_handle() allocates state that curl_free_obj() later frees, but curl_free_obj() does nothing if ch->cp is not set. In curl_clone_obj(), defer that allocation until a valid copied handle exists so failed duplication leaves nothing to clean up. Closes #22899
1 parent ad70bbd commit 3163ac7

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

ext/curl/interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ static zend_object *curl_clone_obj(zend_object *object) {
441441

442442
clone_object = curl_create_object(curl_ce);
443443
clone_ch = curl_from_obj(clone_object);
444-
init_curl_handle(clone_ch);
445444

446445
ch = curl_from_obj(object);
447446
cp = curl_easy_duphandle(ch->cp);
@@ -450,6 +449,7 @@ static zend_object *curl_clone_obj(zend_object *object) {
450449
return &clone_ch->std;
451450
}
452451

452+
init_curl_handle(clone_ch);
453453
clone_ch->cp = cp;
454454
_php_setup_easy_copy_handlers(clone_ch, ch);
455455

0 commit comments

Comments
 (0)