-
Notifications
You must be signed in to change notification settings - Fork 29
SQLFreeStmt(stmt,SQL_DROP) now returns an error when it's conn has been disconnected. #113
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
SQLFreeStmt(stmt,SQL_DROP) now returns an error when it's conn has been disconnected. #113
Conversation
… statement resources when its connection already has been closed. A crash occurred when the PostgreSQL server terminated and a connection was subsequently attempted from an application when connection pooling by the driver manager was enabled and several pooled connections existed. In such cases, an invalid memory access would occur in ENTER_CONN_CS(conn) in SQLFreeStmt(), or an invalid address free() would be attempted in SC_clear_error() via PGAPI_FreeStmt(). "CC_cleanup()" doing "conn->status = CONN_NOT_CONNECTED" releases all statements belonging to the connection, so this change will probably not cause a resource leak.
After continued testing, I found that the earlier fix alone caused crashes in similar attempts, so we improved the fix.
@harukat has this fixed the issue for you ? |
Yes. However, we have subsequently received reports of psqlodbc crashing under similar circumstances after applying this fix. I have not yet been able to analyze this issue and have not established a procedure to reproduce it. |
@davecramer Although this fix reduces the frequency of occurrence, it does not seem to completely prevent the driver manager from attempting to execute SQLFreeStmt(hstmt,SQL_DROP) twice for same hstmt. When connection pooling was enabled and clients were repeatedly connecting, querying, and disconnecting, stopping the PostgreSQL server and having clients repeatedly try to connect could cause hstmt dereference to fail or double free. The following is an excerpt from the call stack as it occurs:
The following is the tail of debug log as it occurs: (hstmt dereference failure case)
|
I created a new PR which attempts to solve your problem see #115 |
SQLFreeStmt(stmt, SQL_DROP) now returns an error before trying to free statement resources
when its connection already has been closed.
A crash occurred when the PostgreSQL server terminated and a connection was subsequently attempted from an application when connection pooling by the driver manager was enabled and several pooled connections existed. In such cases, an invalid memory access would occur in ENTER_CONN_CS(conn) in SQLFreeStmt(), or an invalid address free() would be attempted in SC_clear_error() via PGAPI_FreeStmt().
"CC_cleanup()" doing "conn->status = CONN_NOT_CONNECTED" releases all statements belonging to the connection, so this change will probably not cause a resource leak.