Skip to content

Conversation

@ndossche
Copy link
Member

@ndossche ndossche commented Nov 4, 2025

The return value is already overwritten by this point so we do have to clean up the old return value (i.e. dataset) after all.

The return value is already overwritten by this point so we do have to
clean up the old return value (i.e. dataset) after all.
ZVAL_COPY_VALUE(&dataset, return_value);
zend_result obj_initialized = object_init_ex(return_value, ce);
if (UNEXPECTED(obj_initialized == FAILURE)) {
zval_ptr_dtor(&dataset);
Copy link
Member

Choose a reason for hiding this comment

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

I might confuse but you said to girgias in the other PR

In fact, zval_ptr_dtor(&dataset); should also be dropped as dataset is a borrow of the return value.

Copy link
Member

Choose a reason for hiding this comment

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

Here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was wrong about that. I missed that object_init_ex overwrites the return value also in case of failure

Copy link
Member

Choose a reason for hiding this comment

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

ah true true I see it now.

@ndossche ndossche merged commit 0432395 into php:PHP-8.3 Nov 4, 2025
9 checks passed
ndossche added a commit that referenced this pull request Nov 4, 2025
Both enums and integers map to TidyInteger, however, in the TidyInteger
case we always used zval_get_long(). So for a non-numeric string, this
would get turned into 0. 0 is the first enum value in that case, so the
wrong enum value could be selected.

To solve this, add special handling for strings and (stringable) objects
such that we can explicitly check for numeric strings, and if they're
not, handle them as normal strings instead of as 0.

Closes GH-20387.
ndossche added a commit that referenced this pull request Nov 4, 2025
* PHP-8.3:
  Fix GH-20374: PHP with tidy and custom-tags
  pgsql: Fix memory leak when object init fails (#20387)
ndossche added a commit that referenced this pull request Nov 4, 2025
* PHP-8.4:
  Fix GH-20374: PHP with tidy and custom-tags
  pgsql: Fix memory leak when object init fails (#20387)
ndossche added a commit that referenced this pull request Nov 4, 2025
* PHP-8.5:
  Fix GH-20374: PHP with tidy and custom-tags
  pgsql: Fix memory leak when object init fails (#20387)
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.

2 participants