CSQLiteStmt.Finalize

Started by Paul Squires, March 31, 2019, 11:18:15 AM

Previous topic - Next topic

Paul Squires

Hi Jose,

In the  SQLite class, Finalize gets called during the Destructor and when a new statement is prepared. However, if the programmer calls Finalize in their code then the statement handle m_hStmt needs to be set to zero, otherwise a GPF will occur when the class subsequently tries to call Finalize because the statement will have already been freed and the m_hStmt value is no longer valid.


PRIVATE FUNCTION CSQLiteStmt.Finalize () AS LONG
   DIM pProc AS PFNSQLITE3FINALIZEPROC = _
   cast(PFNSQLITE3FINALIZEPROC, GetProcAddress(m_hLib, "sqlite3_finalize"))
   IF pProc = 0 THEN this.SetResult(GetLastError) : EXIT FUNCTION
   FUNCTION = pProc(m_hStmt)
   m_hStmt = 0  ' <---- NEED TO ADD THIS LINE
   IF m_pColNames THEN m_pColNames->RemoveAll
END FUNCTION

Paul Squires
PlanetSquires Software

José Roca

Done. Thanks for spotting it.