Skip to content

Fix leak when cURL PREREQFUNCTION returns a type other than int#22726

Open
Sjord wants to merge 2 commits into
php:PHP-8.4from
Sjord:leak-curlopt-prereqfunction
Open

Fix leak when cURL PREREQFUNCTION returns a type other than int#22726
Sjord wants to merge 2 commits into
php:PHP-8.4from
Sjord:leak-curlopt-prereqfunction

Conversation

@Sjord

@Sjord Sjord commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

The return value of the function registered with CURLOPT_PREREQFUNCTION was not cleaned up. Destroy the return value. Increase the returned string in the test so that the address sanitizer picks up the leak.

@Sjord Sjord requested a review from adoy as a code owner July 14, 2026 11:27
Comment thread ext/curl/tests/curl_setopt_CURLOPT_PREREQFUNCTION.phpt Outdated
Sjord added 2 commits July 14, 2026 11:47
The return value of the function registered with CURLOPT_PREREQFUNCTION
was not cleaned up. Destroy the return value. Increase the returned
string in the test so that the address sanitizer picks up the leak.
The CURLOPT_PREREQFUNCTION leak test returned a constant string value.
Under opcache optimization, SCCP/constant folding may turn this into
an interned string, which is process-lifetime allocated and therefore
does not reliably trigger leak detection.

Use a dynamically allocated array containing random_bytes() instead.
This guarantees a non-interned, refcounted return value that exercises
the missing zval_ptr_dtor() path consistently under leak analyzers.
@Sjord Sjord force-pushed the leak-curlopt-prereqfunction branch from c7cf248 to d7b9b3f Compare July 14, 2026 11:48
@Sjord Sjord requested a review from ndossche July 14, 2026 11:50
@ndossche ndossche changed the title Fix leak when cURL PREREQFUNCTION returns a string Fix leak when cURL PREREQFUNCTION returns a type other than int Jul 14, 2026

@ndossche ndossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

Note that the callbacks in curl all have a shared issue: none of them handles references correctly. This is not blocking for your PR of course, but should be fixed some day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants