Skip to content

Commit

Permalink
Fix memory handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fila43 committed Sep 16, 2024
1 parent c6484cb commit 90cd633
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ DB_::~DB_() {

Libdb::Libdb(){
database_type = DB_type::LIBDB;
cursorp = nullptr;
db = nullptr;
};

bool Libdb::connect_database(std::string path){
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 90cd633

Please sign in to comment.