Skip to content

ext/mysqli: Fix memory leak and missing error handling in mysqli_poll.#21408

Open
devnexen wants to merge 3 commits intophp:PHP-8.4from
devnexen:mysqlnd_zval_array_from_mysqlnd_array_leak_fix
Open

ext/mysqli: Fix memory leak and missing error handling in mysqli_poll.#21408
devnexen wants to merge 3 commits intophp:PHP-8.4from
devnexen:mysqlnd_zval_array_from_mysqlnd_array_leak_fix

Conversation

@devnexen
Copy link
Member

In mysqlnd_zval_array_from_mysqlnd_array, dest_array was not released on the error path. Also the callers were not checking the return value.

Found via static analysis, the error path is difficult to trigger in practice.

In mysqlnd_zval_array_from_mysqlnd_array, dest_array was not released
on the error path. Also the callers were not checking the return value.

Found via static analysis, the error path is difficult to trigger in
practice.
@devnexen devnexen marked this pull request as ready for review March 10, 2026 21:56
MYSQLI_RESOURCE *my_res;
mysqli_object *intern = Z_MYSQLI_P(elem);
if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
zval_ptr_dtor(&dest_array);
Copy link
Member

Choose a reason for hiding this comment

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

Should it be zval_ptr_dtor(&dest_array) or zval_ptr_dtor(dest_array)?

Copy link
Member Author

@devnexen devnexen Mar 11, 2026

Choose a reason for hiding this comment

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

The first, it is zval dest_array;.

Copy link
Member

Choose a reason for hiding this comment

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

Did you drop this change? Why can I not see it anymore?

@kamil-tekiela
Copy link
Member

I'm pretty sure that this is an impossible scenario. Why not replace it with an assert?

return FAILURE;
}
my_res = (MYSQLI_RESOURCE *)intern->ptr;
ZEND_ASSERT(my_res);
Copy link
Member

Choose a reason for hiding this comment

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

And because this is now an assertion, the function can only ever return SUCCESS, making the return value unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes I realise those are only internal helpers not APIS ...

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