Skip to content

Fix double-free / heap corruption during SQLDisconnect cleanup (#189)#190

Merged
davecramer merged 1 commit into
postgresql-interfaces:mainfrom
davecramer:fix_issue_189
May 30, 2026
Merged

Fix double-free / heap corruption during SQLDisconnect cleanup (#189)#190
davecramer merged 1 commit into
postgresql-interfaces:mainfrom
davecramer:fix_issue_189

Conversation

@davecramer
Copy link
Copy Markdown
Contributor

CC_cleanup() was freeing statement and descriptor objects via SC_Destructor(), but the ODBC Driver Manager still held handles to them. When the DM later called SQLFreeStmt(SQL_DROP) via SQLFreeHandle(), the driver dereferenced freed memory, causing the double-free detected by Application Verifier with Page Heap enabled.

Fix by detaching statements/descriptors in CC_cleanup() without freeing them. The DM will free them later through the normal SQLFreeHandle path. Also allow SQLFreeStmt(SQL_DROP) to proceed when hdbc is NULL (the expected state after disconnect), and remove misleading error-return logic in SC_Destructor that reported failure after already freeing.

…resql-interfaces#189)

CC_cleanup() was freeing statement and descriptor objects via
SC_Destructor(), but the ODBC Driver Manager still held handles to them.
When the DM later called SQLFreeStmt(SQL_DROP) via SQLFreeHandle(), the
driver dereferenced freed memory, causing the double-free detected by
Application Verifier with Page Heap enabled.

Fix by detaching statements/descriptors in CC_cleanup() without freeing
them. The DM will free them later through the normal SQLFreeHandle path.
Also allow SQLFreeStmt(SQL_DROP) to proceed when hdbc is NULL (the
expected state after disconnect), and remove misleading error-return
logic in SC_Destructor that reported failure after already freeing.
@davecramer davecramer merged commit 56f3422 into postgresql-interfaces:main May 30, 2026
6 checks passed
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.

Possible double-free / heap corruption in psqlODBC during SQLDisconnect cleanup

1 participant