Permalink
Browse files

Issue 82: Crash on Windows if cursor freed after cnxn (sometimes)

Crash due to using HSTMT while cleaning up parameters after the connection is
closed.  Unfortunately I wasn't able to put together an easy test case without
using the with statement like the reporter did.
  • Loading branch information...
1 parent b15987b commit e998b116d8341c552cc8a2d2dea02026d00504f3 @mkleehammer committed Dec 31, 2009
Showing with 8 additions and 3 deletions.
  1. +8 −3 src/params.cpp
View
@@ -24,9 +24,14 @@ void FreeParameterData(Cursor* cur)
if (cur->paramdata)
{
- Py_BEGIN_ALLOW_THREADS
- SQLFreeStmt(cur->hstmt, SQL_RESET_PARAMS);
- Py_END_ALLOW_THREADS
+ // MS ODBC will crash if we use an HSTMT after the HDBC has been freed.
+ if (cur->cnxn->hdbc != SQL_NULL_HANDLE)
+ {
+ Py_BEGIN_ALLOW_THREADS
+ SQLFreeStmt(cur->hstmt, SQL_RESET_PARAMS);
+ Py_END_ALLOW_THREADS
+ }
+
free(cur->paramdata);
cur->paramdata = 0;
}

0 comments on commit e998b11

Please sign in to comment.