security: fix memory leak in SecPublicInfoSqlite3
refs #2253
Change-Id: I8831bfa81498e9757e797218e83fd31010e2a186
diff --git a/src/security/sec-public-info-sqlite3.cpp b/src/security/sec-public-info-sqlite3.cpp
index c147bf1..946eb56 100644
--- a/src/security/sec-public-info-sqlite3.cpp
+++ b/src/security/sec-public-info-sqlite3.cpp
@@ -22,8 +22,6 @@
* @author Jeff Thompson <jefft0@remap.ucla.edu>
*/
-#include "common.hpp"
-
#include "sec-public-info-sqlite3.hpp"
#include "identity-certificate.hpp"
#include "signature-sha256-with-rsa.hpp"
@@ -104,6 +102,7 @@
}
SecPublicInfoSqlite3::SecPublicInfoSqlite3()
+ : m_database(nullptr)
{
boost::filesystem::path identityDir = boost::filesystem::path(getenv("HOME")) / ".ndn";
boost::filesystem::create_directories(identityDir);
@@ -120,6 +119,8 @@
if (res != SQLITE_OK)
throw Error("identity DB cannot be opened/created");
+ BOOST_ASSERT(m_database != nullptr);
+
//Check if Key table exists;
sqlite3_stmt* statement;
sqlite3_prepare_v2(m_database,
@@ -187,6 +188,8 @@
SecPublicInfoSqlite3::~SecPublicInfoSqlite3()
{
+ sqlite3_close(m_database);
+ m_database = nullptr;
}
bool
diff --git a/src/security/sec-public-info-sqlite3.hpp b/src/security/sec-public-info-sqlite3.hpp
index f66b188..beaff10 100644
--- a/src/security/sec-public-info-sqlite3.hpp
+++ b/src/security/sec-public-info-sqlite3.hpp
@@ -129,9 +129,9 @@
setDefaultCertificateNameForKeyInternal(const Name& certificateName);
private:
- sqlite3 * m_database;
+ sqlite3* m_database;
};
} // namespace ndn
-#endif //NDN_SECURITY_SEC_PUBLIC_INFO_SQLITE3_HPP
+#endif // NDN_SECURITY_SEC_PUBLIC_INFO_SQLITE3_HPP