Skip to content

Fix memory leaks when sk_X509_new_null() fails#20957

Closed
ndossche wants to merge 1 commit intophp:PHP-8.4from
ndossche:clesss-1
Closed

Fix memory leaks when sk_X509_new_null() fails#20957
ndossche wants to merge 1 commit intophp:PHP-8.4from
ndossche:clesss-1

Conversation

@ndossche
Copy link
Copy Markdown
Member

@ndossche ndossche commented Jan 17, 2026

In a lot of places the return value is not checked, and when the function fails the code continues execution. However, this means that operations on the stack fail and will cause memory leaks on the objects that weren't pushed.

We also notice an inconsistency in how these failures are handled. For example, in one place we explicitly have a fatal error php_error_docref(NULL, E_ERROR, "Memory allocation failure"); but this is the only place to do so.

This was found by a hybrid static-dynamic analyser that looks for inconsistent handling of error checks in bindings.

In a lot of places the return value is not checked, and when the
function fails the code continues execution. However, this means that
operations on the stack fail and will cause memory leaks on the objects
that weren't pushed.

We also notice an inconsistency in how these failures are handled.
For example, in one place we explicitly have a fatal error
`php_error_docref(NULL, E_ERROR, "Memory allocation failure");`
but this is the only place to do so.
Comment thread ext/openssl/openssl.c
@bukka
Copy link
Copy Markdown
Member

bukka commented Jan 17, 2026

I guess you can just get rid of that warning. In reality it won't likely get printed / visible anyway if there is no memory left...

@ndossche ndossche closed this in 7754eaf Jan 22, 2026
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.

4 participants