Add a Statement::Ptr move constructor to fix leak because of ref counter incremented on copy

This commit is contained in:
Sébastien Rombauts 2019-03-05 00:20:06 +01:00
parent 13c5d4f00c
commit f2b1017710
2 changed files with 18 additions and 0 deletions

View File

@ -654,6 +654,12 @@ private:
Ptr(sqlite3* apSQLite, std::string& aQuery);
// Copy constructor increments the ref counter
Ptr(const Ptr& aPtr);
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)
// Move constructor
Ptr(Ptr&& aPtr);
#endif
// Decrement the ref counter and finalize the sqlite3_stmt when it reaches 0
~Ptr();

View File

@ -456,6 +456,18 @@ Statement::Ptr::Ptr(const Statement::Ptr& aPtr) :
++(*mpRefCount);
}
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)
Statement::Ptr::Ptr(Ptr&& aPtr) :
mpSQLite(aPtr.mpSQLite),
mpStmt(aPtr.mpStmt),
mpRefCount(aPtr.mpRefCount)
{
aPtr.mpSQLite = NULL;
aPtr.mpStmt = NULL;
aPtr.mpRefCount = NULL;
}
#endif
/**
* @brief Decrement the ref counter and finalize the sqlite3_stmt when it reaches 0
*/