psqlodbc.git / summary / log / commit / refs
commit 7065a7af196bb09f80beddce82fa728c8a6dfcba
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Thu Feb 20 07:09:47 2014 +0000
Add locking to SQLFreeStmt and SQLFreeHandle.
This fixes a race condition, where SQLFreeStmt is called while the
connection is busy executing another statement. SC_set_prepared would see
that the connection is busy (CONN_EXECUTING), and not issue a DEALLOCATE
statement to free the prepared statement in the backend, leaking it.
odbcapi.c | 27 +++++++++++++++++++++++++++
odbcapi30.c | 17 +++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/odbcapi.c b/odbcapi.c
index fc124d5b..efcd480f 100644
--- a/odbcapi.c
+++ b/odbcapi.c
@@ -455,9 +455,36 @@ SQLFreeStmt(HSTMT StatementHandle,
SQLUSMALLINT Option)
{
RETCODE ret;
+ StatementClass *stmt = (StatementClass *) StatementHandle;
+ ConnectionClass *conn = NULL;
mylog("[SQLFreeStmt]");
+
+ if (stmt)
+ {
+ if (Option == SQL_DROP)
+ {
+ conn = stmt->hdbc;
+ if (conn)
+ ENTER_CONN_CS(conn);
+ }
+ else
+ ENTER_STMT_CS(stmt);
+ }
+
ret = PGAPI_FreeStmt(StatementHandle, Option);
+
+ if (stmt)
+ {
+ if (Option == SQL_DROP)
+ {
+ if (conn)
+ LEAVE_CONN_CS(conn);
+ }
+ else
+ LEAVE_STMT_CS(stmt);
+ }
+
return ret;
}
diff --git a/odbcapi30.c b/odbcapi30.c
index 16288bb7..4a99a4e6 100644
--- a/odbcapi30.c
+++ b/odbcapi30.c
@@ -239,7 +239,11 @@ SQLFreeHandle(SQLSMALLINT HandleType, SQLHANDLE Handle)
{
CSTR func = "SQLFreeHandle";
RETCODE ret;
+ StatementClass *stmt;
+ ConnectionClass *conn = NULL;
+
mylog("[[%s]]", func);
+
switch (HandleType)
{
case SQL_HANDLE_ENV:
@@ -249,7 +253,20 @@ SQLFreeHandle(SQLSMALLINT HandleType, SQLHANDLE Handle)
ret = PGAPI_FreeConnect(Handle);
break;
case SQL_HANDLE_STMT:
+ stmt = (StatementClass *) Handle;
+
+ if (stmt)
+ {
+ conn = stmt->hdbc;
+ if (conn)
+ ENTER_CONN_CS(conn);
+ }
+
ret = PGAPI_FreeStmt(Handle, SQL_DROP);
+
+ if (conn)
+ LEAVE_CONN_CS(conn);
+
break;
case SQL_HANDLE_DESC:
ret = PGAPI_FreeDesc(Handle);
[parent: 3116f70ab51d]