1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

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.
This commit is contained in:
Niels Dossche
2025-05-30 21:03:41 +02:00
parent 48b492269b
commit d9d991928f
2 changed files with 7 additions and 2 deletions

3
NEWS
View File

@@ -6,6 +6,9 @@ PHP NEWS
. Fixed GH-18695 (zend_ast_export() - float number is not preserved).
(Oleg Efimov)
- Curl:
. Fix memory leak when setting a list via curl_setopt fails. (nielsdos)
- Date:
. Fix leaks with multiple calls to DatePeriod iterator current(). (nielsdos)

View File

@@ -2220,12 +2220,14 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
ZEND_HASH_FOREACH_VAL(ph, current) {
ZVAL_DEREF(current);
val = zval_get_tmp_string(current, &tmp_val);
slist = curl_slist_append(slist, ZSTR_VAL(val));
struct curl_slist *new_slist = curl_slist_append(slist, ZSTR_VAL(val));
zend_tmp_string_release(tmp_val);
if (!slist) {
if (!new_slist) {
curl_slist_free_all(slist);
php_error_docref(NULL, E_WARNING, "Could not build curl_slist");
return FAILURE;
}
slist = new_slist;
} ZEND_HASH_FOREACH_END();
if (slist) {