Skip to content

Commit

Permalink
fix curl multi mem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 20, 2021
1 parent a79bd50 commit 91bf243
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ext-src/php_swoole_curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class Multi {
curl_multi_setopt(multi_handle_, CURLMOPT_TIMERDATA, this);
}

~Multi() {
curl_multi_cleanup(multi_handle_);
}

CURLM *get_multi_handle() {
return multi_handle_;
}
Expand Down
9 changes: 7 additions & 2 deletions thirdparty/php/curl/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,13 @@ void _php_curl_free(php_curl *ch) {
curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_nothing);
curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write_nothing);

swoole::curl::Handle *handle = nullptr;
curl_easy_getinfo(ch->cp, CURLINFO_PRIVATE, &handle);

if (handle && handle->multi) {
handle->multi->remove_handle(ch);
}

/* cURL destructors should be invoked only by last curl handle */
if (--(*ch->clone) == 0) {
zend_llist_clean(&ch->to_free->str);
Expand All @@ -2701,8 +2708,6 @@ void _php_curl_free(php_curl *ch) {
efree(ch->to_free);
efree(ch->clone);

swoole::curl::Handle *handle = nullptr;
curl_easy_getinfo(ch->cp, CURLINFO_PRIVATE, &handle);
delete handle;
curl_easy_setopt(ch->cp, CURLOPT_PRIVATE, nullptr);
}
Expand Down
1 change: 0 additions & 1 deletion thirdparty/php/curl/multi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,6 @@ static void _php_curl_multi_free(php_curlm *mh) {
mh->multi->remove_handle(ch->cp);
}
}
curl_multi_cleanup(mh->multi->get_multi_handle());
zend_llist_clean(&mh->easyh);
if (mh->handlers->server_push) {
zval_ptr_dtor(&mh->handlers->server_push->func_name);
Expand Down

0 comments on commit 91bf243

Please sign in to comment.