Skip to content

Commit d20129b

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 f6fe838 commit d20129b

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
@@ -400,7 +400,6 @@ static zend_object *curl_clone_obj(zend_object *object) {
400400

401401
clone_object = curl_create_object(curl_ce);
402402
clone_ch = curl_from_obj(clone_object);
403-
init_curl_handle(clone_ch);
404403

405404
ch = curl_from_obj(object);
406405
cp = curl_easy_duphandle(ch->cp);
@@ -409,6 +408,7 @@ static zend_object *curl_clone_obj(zend_object *object) {
409408
return &clone_ch->std;
410409
}
411410

411+
init_curl_handle(clone_ch);
412412
clone_ch->cp = cp;
413413
_php_setup_easy_copy_handlers(clone_ch, ch);
414414

0 commit comments

Comments
 (0)