Skip to content

Commit 899f57d

Browse files
committed
Fix mem leak when duphandle fails in curl_clone_obj
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.
1 parent 68d605f commit 899f57d

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)