Skip to content

Commit cc5d02a

Browse files
authored
SQLFreeStmt(stmt,SQL_DROP) now returns an error when it's conn has been disconnected. (#113)
* 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. * Make 4dc08c8 more robust. After continued testing, I found that the earlier fix alone caused crashes in similar attempts, so we improved the fix.
1 parent c8cb6cf commit cc5d02a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

odbcapi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,12 @@ SQLFreeStmt(HSTMT StatementHandle,
399399
if (Option == SQL_DROP)
400400
{
401401
conn = stmt->hdbc;
402+
if (!conn || (conn->status != CONN_CONNECTED && conn->status != CONN_EXECUTING))
403+
return SQL_INVALID_HANDLE;
402404
if (conn)
403405
ENTER_CONN_CS(conn);
406+
if (!conn || (conn->status != CONN_CONNECTED && conn->status != CONN_EXECUTING))
407+
return SQL_INVALID_HANDLE;
404408
}
405409
else
406410
ENTER_STMT_CS(stmt);

0 commit comments

Comments
 (0)