PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CSQLiteStmt.Finalize  (Read 184 times)

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8782
  • Windows 10
    • PlanetSquires Software
CSQLiteStmt.Finalize
« on: March 31, 2019, 10:48:15 AM »

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.

Code: [Select]
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
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3177
Re: CSQLiteStmt.Finalize
« Reply #1 on: March 31, 2019, 11:27:28 AM »

Done. Thanks for spotting it.