From 90cd633105ba6c29f072c2f048dbcde7e386350b Mon Sep 17 00:00:00 2001 From: Filip Date: Mon, 16 Sep 2024 16:22:02 +0200 Subject: [PATCH] Fix memory handling In case of a non-valid input file, the program warned about the situation, but in the destructor was accessed uninitialized memory. This leads to a Core dump. --- db.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/db.cc b/db.cc index ee8962c..1f815a5 100644 --- a/db.cc +++ b/db.cc @@ -22,6 +22,8 @@ DB_::~DB_() { Libdb::Libdb(){ database_type = DB_type::LIBDB; + cursorp = nullptr; + db = nullptr; }; bool Libdb::connect_database(std::string path){ @@ -52,8 +54,10 @@ DBC * Libdb::get_database(){ } void Libdb::close_db() { - cursorp->close(cursorp); - db->close(db, 0); + if (cursorp != nullptr) + cursorp->close(cursorp); + if (db != nullptr) + db->close(db, 0); } Libdb::~Libdb() {