Skip to content

Commit 91bf243

Browse files
committed
fix curl multi mem leak
1 parent a79bd50 commit 91bf243

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

ext-src/php_swoole_curl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class Multi {
108108
curl_multi_setopt(multi_handle_, CURLMOPT_TIMERDATA, this);
109109
}
110110

111+
~Multi() {
112+
curl_multi_cleanup(multi_handle_);
113+
}
114+
111115
CURLM *get_multi_handle() {
112116
return multi_handle_;
113117
}

thirdparty/php/curl/interface.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,13 @@ void _php_curl_free(php_curl *ch) {
26912691
curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_nothing);
26922692
curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write_nothing);
26932693

2694+
swoole::curl::Handle *handle = nullptr;
2695+
curl_easy_getinfo(ch->cp, CURLINFO_PRIVATE, &handle);
2696+
2697+
if (handle && handle->multi) {
2698+
handle->multi->remove_handle(ch);
2699+
}
2700+
26942701
/* cURL destructors should be invoked only by last curl handle */
26952702
if (--(*ch->clone) == 0) {
26962703
zend_llist_clean(&ch->to_free->str);
@@ -2701,8 +2708,6 @@ void _php_curl_free(php_curl *ch) {
27012708
efree(ch->to_free);
27022709
efree(ch->clone);
27032710

2704-
swoole::curl::Handle *handle = nullptr;
2705-
curl_easy_getinfo(ch->cp, CURLINFO_PRIVATE, &handle);
27062711
delete handle;
27072712
curl_easy_setopt(ch->cp, CURLOPT_PRIVATE, nullptr);
27082713
}

thirdparty/php/curl/multi.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ static void _php_curl_multi_free(php_curlm *mh) {
731731
mh->multi->remove_handle(ch->cp);
732732
}
733733
}
734-
curl_multi_cleanup(mh->multi->get_multi_handle());
735734
zend_llist_clean(&mh->easyh);
736735
if (mh->handlers->server_push) {
737736
zval_ptr_dtor(&mh->handlers->server_push->func_name);

0 commit comments

Comments
 (0)