From: <br...@us...> - 2004-01-21 21:53:41
|
Update of /cvsroot/htoolkit/HSQL/ODBC In directory sc8-pr-cvs1:/tmp/cvs-serv25484 Modified Files: HSQL.hsc Log Message: Previously, calling closeStatement twice on the same statement would cause hSTMT and fetchBuffer to be freed twice (whic is not a Good Thing). I added an IORef Bool field to Statement to keep track of whether the statement has already been closed. Index: HSQL.hsc =================================================================== RCS file: /cvsroot/htoolkit/HSQL/ODBC/HSQL.hsc,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** HSQL.hsc 21 Jan 2004 21:17:19 -0000 1.20 --- HSQL.hsc 21 Jan 2004 21:53:38 -0000 1.21 *************** *** 107,110 **** --- 107,111 ---- , fetchBuffer :: !(Ptr ()) , fetchBufferSize :: !SQLINTEGER + , closed :: !(IORef Bool) -- To avoid freeing hSTMT and fetchBuffer twice } *************** *** 293,297 **** free pFIELD buffer <- mallocBytes (fromIntegral bufSize) ! let statement = Statement {hSTMT=hSTMT, connection=conn, fields=fields, fetchBuffer=buffer, fetchBufferSize=bufSize} return statement where --- 294,300 ---- free pFIELD buffer <- mallocBytes (fromIntegral bufSize) ! closed <- newIORef False ! let statement = Statement {hSTMT=hSTMT, connection=conn, fields=fields, ! fetchBuffer=buffer, fetchBufferSize=bufSize, closed=closed} return statement where *************** *** 362,367 **** closeStatement :: Statement -> IO () closeStatement stmt = do ! free (fetchBuffer stmt) ! sqlFreeStmt (hSTMT stmt) 0 >>= handleSqlResult (#const SQL_HANDLE_STMT) (hSTMT stmt) ----------------------------------------------------------------------------------------- --- 365,376 ---- closeStatement :: Statement -> IO () closeStatement stmt = do ! alreadyClosed <- readIORef (closed stmt) ! unless alreadyClosed realClose ! where ! realClose = do ! free (fetchBuffer stmt) ! sqlFreeStmt (hSTMT stmt) 0 >>= handleSqlResult (#const SQL_HANDLE_STMT) (hSTMT stmt) ! writeIORef (closed stmt) True ! ----------------------------------------------------------------------------------------- |