Skip to content

Fix GH-21162: pg_connect() on error memory leak.#21165

Closed
devnexen wants to merge 2 commits intophp:PHP-8.4from
devnexen:gh21162
Closed

Fix GH-21162: pg_connect() on error memory leak.#21165
devnexen wants to merge 2 commits intophp:PHP-8.4from
devnexen:gh21162

Conversation

@devnexen
Copy link
Member

@devnexen devnexen commented Feb 8, 2026

The PHP_PQ_ERROR macro calls php_error_docref() which triggers user error handlers thus libpq does not have the chance to clean the resources (and empty connections string are allowed) on failure thus we avoid this macro and delay the error handling after.

The PHP_PQ_ERROR macro calls php_error_docref() which triggers user error handlers
thus libpq does not have the chance to clean the resources (and empty
connections string are allowed) on failure thus we avoid this macro
and delay the error handling after.
@devnexen devnexen marked this pull request as ready for review February 9, 2026 19:23
@devnexen devnexen requested a review from Girgias February 9, 2026 19:23
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Does it make sense to remove the PHP_PQ_ERROR macro?

@devnexen
Copy link
Member Author

No it is still used in other contexts.

@devnexen devnexen closed this in 539c5d9 Feb 15, 2026
@iluuu1994
Copy link
Member

@devnexen Please check why this fails on Windows. https://github.com/php/php-src/actions/runs/22043379618/job/63687927421

Did you get e-mail notifications about failing pushed commits? If not, can you enable it here?

https://github.com/settings/notifications

image

@devnexen
Copy link
Member Author

@devnexen Please check why this fails on Windows. https://github.com/php/php-src/actions/runs/22043379618/job/63687927421

Did you get e-mail notifications about failing pushed commits? If not, can you enable it here?

https://github.com/settings/notifications

image

Sorry I was very unavailable today I ll able to check in less than 1h. Cheers

@devnexen
Copy link
Member Author

So it seems the error handler does not trigger on windows ? but since that s the whole point of the bug, should I just disable on windows, wdyt @iluuu1994 ?

devnexen added a commit to devnexen/php-src that referenced this pull request Feb 16, 2026
skipping on windows as the error handler does not seem to trigger.
@iluuu1994
Copy link
Member

iluuu1994 commented Feb 16, 2026

I don't know, I don't even know what warning is being triggered, since the message is discarded. Do you know why this isn't triggered on Windows specifically?

@devnexen
Copy link
Member Author

not entirely sure, what can help it to see if pg_connect with an empty string behaves differently on windows. on unix => attempts to open an unix socket => does not work => error. on windows I m not sure yet what is the workflow.

devnexen added a commit that referenced this pull request Feb 17, 2026
making it fails early instead.

close GH-21234
devnexen added a commit that referenced this pull request Feb 17, 2026
* PHP-8.4:
  ext/pgsql: fix GH-21165 unit test.
devnexen added a commit that referenced this pull request Feb 17, 2026
* PHP-8.5:
  ext/pgsql: fix GH-21165 unit test.
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