Skip to content

Commit d9d9919

Browse files
committed
Fix memory leak when curl_slist_append() fails
If curl_slist_append() returns NULL, then the original pointer is lost and not freed. Closes GH-18711.
1 parent 48b4922 commit d9d9919

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed GH-18695 (zend_ast_export() - float number is not preserved).
77
(Oleg Efimov)
88

9+
- Curl:
10+
. Fix memory leak when setting a list via curl_setopt fails. (nielsdos)
11+
912
- Date:
1013
. Fix leaks with multiple calls to DatePeriod iterator current(). (nielsdos)
1114

ext/curl/interface.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,12 +2220,14 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
22202220
ZEND_HASH_FOREACH_VAL(ph, current) {
22212221
ZVAL_DEREF(current);
22222222
val = zval_get_tmp_string(current, &tmp_val);
2223-
slist = curl_slist_append(slist, ZSTR_VAL(val));
2223+
struct curl_slist *new_slist = curl_slist_append(slist, ZSTR_VAL(val));
22242224
zend_tmp_string_release(tmp_val);
2225-
if (!slist) {
2225+
if (!new_slist) {
2226+
curl_slist_free_all(slist);
22262227
php_error_docref(NULL, E_WARNING, "Could not build curl_slist");
22272228
return FAILURE;
22282229
}
2230+
slist = new_slist;
22292231
} ZEND_HASH_FOREACH_END();
22302232

22312233
if (slist) {

0 commit comments

Comments
 (0)