From 50425142fec09849c8114f8a042d72f5bcf7f5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Tue, 5 Mar 2019 07:15:06 +0100 Subject: [PATCH] Fix Statement destructor since addition of the move constructor --- src/Statement.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Statement.cpp b/src/Statement.cpp index 1dd9bdf..5c285d6 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -466,30 +466,32 @@ Statement::Ptr::Ptr(Ptr&& aPtr) : aPtr.mpStmt = NULL; aPtr.mpRefCount = NULL; } -#endif +#endif /** * @brief Decrement the ref counter and finalize the sqlite3_stmt when it reaches 0 */ Statement::Ptr::~Ptr() { - assert(NULL != mpRefCount); - assert(0 != *mpRefCount); - - // Decrement and check the reference counter of the sqlite3_stmt - --(*mpRefCount); - if (0 == *mpRefCount) + if (NULL != mpRefCount) { - // If count reaches zero, finalize the sqlite3_stmt, as no Statement nor Column objet use it anymore. - // No need to check the return code, as it is the same as the last statement evaluation. - sqlite3_finalize(mpStmt); + assert(0 != *mpRefCount); - // and delete the reference counter - delete mpRefCount; - mpRefCount = NULL; - mpStmt = NULL; + // Decrement and check the reference counter of the sqlite3_stmt + --(*mpRefCount); + if (0 == *mpRefCount) + { + // If count reaches zero, finalize the sqlite3_stmt, as no Statement nor Column objet use it anymore. + // No need to check the return code, as it is the same as the last statement evaluation. + sqlite3_finalize(mpStmt); + + // and delete the reference counter + delete mpRefCount; + mpRefCount = NULL; + mpStmt = NULL; + } + // else, the finalization will be done later, by the last object } - // else, the finalization will be done later, by the last object }