8000 Fix memory leak when curl_slist_append() fails by nielsdos · Pull Request #18711 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content

Fix memory leak when curl_slist_append() fails #18711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix memory leak when curl_slist_append() fails
If curl_slist_append() returns NULL, then the original pointer is lost
and not freed.
  • Loading branch information
nielsdos committed May 30, 2025
commit 1581f6f2b4bd024c5efe194c07b5da6ee9da281d
6 changes: 4 additions & 2 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading
0