diff --git a/convert.cc b/convert.cc index 972564d..63377fe 100755 --- a/convert.cc +++ b/convert.cc @@ -56,8 +56,8 @@ int main(int argc, char* argv[]){ DB_ * x = new Libdb(); if (!x->connect_database(src)) { // error is printed in the connect_database function - delete x; - return 1; + delete x; + return 1; } DB_ *b; if (lmdb) @@ -67,15 +67,19 @@ int main(int argc, char* argv[]){ if (!b->create_database(dst)) { std::cerr<<"Failed to create destination database\n"; delete x; + x->close_db(); delete b; return 1; } if (!b->fill_database(x)){ std::cerr<<"database filling failed\n"; + x->close_db(); + b->close_db(); delete x; delete b; return 1; } + x->close_db(); b->close_db(); delete x; delete b; diff --git a/convert_db.h b/convert_db.h index 2299f41..e11b8d3 100644 --- a/convert_db.h +++ b/convert_db.h @@ -39,7 +39,7 @@ class DB_ { virtual bool fill_database(DB_ * old_database); virtual void close_db(); virtual DBC * get_database(); - virtual ~DB_(); + virtual ~DB_(); }; /* * Libdb class needs only open and read data from libdb database @@ -54,6 +54,7 @@ class Libdb: public DB_ { Libdb(); bool connect_database(std::string path); DBC * get_database(); + void close_db(); }; /* * GDBM class provides API for GDBM, allowes to open and create and fill gdbm database diff --git a/db.cc b/db.cc index b0941c7..119b165 100644 --- a/db.cc +++ b/db.cc @@ -52,6 +52,11 @@ DBC * Libdb::get_database(){ return this->cursorp; } +void Libdb::close_db() { + cursorp->close(cursorp); + db->close(db, 0); +} + GDBM_::GDBM_(){ database_type = DB_type::GDBM; }