Skip to content

fix: use pgfree for libpq mallocs #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025

Conversation

ColinKYuen
Copy link
Contributor

Summary

Uses libqpq's Free for libqpq malloc'd String

Description

Changes the generic free() function for the error message string allocated by PQconninfoParse(..) to use libpq's PQfreemem(..)

As per PostgreSQL's libqpq documents, when using PQconninfoParse(..):

... After processing the options array, free it by passing it to PQconninfoFree. If this is not done, some memory is leaked for each call to PQconninfoParse. Conversely, if an error occurs and errmsg is not NULL, be sure to free the error string using PQfreemem.

Additional information on PQfreemem, this change is only needed for Windows

Frees memory allocated by libpq, particularly PQescapeByteaConn, PQescapeBytea, PQunescapeBytea, and PQnotifies. It is particularly important that this function, rather than free(), be used on Microsoft Windows. This is because allocating memory in a DLL and releasing it in the application works only if multithreaded/single-threaded, release/debug, and static/dynamic flags are the same for the DLL and the application. On non-Microsoft Windows platforms, this function is the same as the standard library function free().

@davecramer davecramer merged commit 505ae7b into postgresql-interfaces:main Apr 24, 2025
1 check passed
@ColinKYuen ColinKYuen deleted the pgfreemem branch April 24, 2025 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants