From e7d98ddfdae1c56d5cc77a2f8f71bec85a094fad Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Thu, 4 Mar 2021 19:35:03 +0900 Subject: [PATCH] Fix memory leak --- src/common/database/db_handle_provider.cc | 14 +++++++++----- src/common/database/db_handle_provider.hh | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/common/database/db_handle_provider.cc b/src/common/database/db_handle_provider.cc index 6acb4b2..d97c132 100644 --- a/src/common/database/db_handle_provider.cc +++ b/src/common/database/db_handle_provider.cc @@ -26,14 +26,18 @@ namespace pkgmgr_common { std::unordered_map> DBHandleProvider::provider_; +bool DBHandleProvider::is_memory_ = false; -const char kMemoryDBPrefix[] = "file:memdb_"; -const char kMemoryDBPostFix[] = "?mode=memory&cache=shared"; -DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid), is_memory_(false), +DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid), parser_memory_db_handle_(nullptr, sqlite3_close_v2), cert_memory_db_handle_(nullptr, sqlite3_close_v2) { - parser_file_db_path_ = getUserPkgParserDBPathUID(uid_); - cert_file_db_path_ = getUserPkgCertDBPath(); + char* tmp_path = getUserPkgParserDBPathUID(uid_); + parser_file_db_path_ = tmp_path; + free(tmp_path); + + tmp_path = getUserPkgCertDBPath(); + cert_file_db_path_ = tmp_path; + free(tmp_path); parser_memory_db_path_ = "file:parserdb" + std::to_string(static_cast(uid_)) + "?mode=memory&cache=shared"; diff --git a/src/common/database/db_handle_provider.hh b/src/common/database/db_handle_provider.hh index a855ad7..59a7c6f 100644 --- a/src/common/database/db_handle_provider.hh +++ b/src/common/database/db_handle_provider.hh @@ -51,7 +51,7 @@ class DBHandleProvider { std::string parser_file_db_path_; std::string cert_memory_db_path_; std::string cert_file_db_path_; - bool is_memory_; + static bool is_memory_; std::mutex lock_; }; -- 2.7.4