Skip to content

Commit 90cd633

Browse files
committed
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.
1 parent c6484cb commit 90cd633

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

db.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ DB_::~DB_() {
2222

2323
Libdb::Libdb(){
2424
database_type = DB_type::LIBDB;
25+
cursorp = nullptr;
26+
db = nullptr;
2527
};
2628

2729
bool Libdb::connect_database(std::string path){
@@ -52,8 +54,10 @@ DBC * Libdb::get_database(){
5254
}
5355

5456
void Libdb::close_db() {
55-
cursorp->close(cursorp);
56-
db->close(db, 0);
57+
if (cursorp != nullptr)
58+
cursorp->close(cursorp);
59+
if (db != nullptr)
60+
db->close(db, 0);
5761
}
5862

5963
Libdb::~Libdb() {

0 commit comments

Comments
 (0)