From: Ondrej Kuznik Date: Fri, 24 Aug 2012 12:28:36 +0000 (-0700) Subject: ITS#7369 mdb_stat: cleanup in case something went wrong. X-Git-Tag: OPENLDAP_REL_ENG_2_4_33~31^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bd92b570a8a3389a5e6bd86abcce2722919f8363;p=openldap ITS#7369 mdb_stat: cleanup in case something went wrong. --- diff --git a/libraries/libmdb/mdb_stat.c b/libraries/libmdb/mdb_stat.c index 5832e267c7..6007510c6b 100644 --- a/libraries/libmdb/mdb_stat.c +++ b/libraries/libmdb/mdb_stat.c @@ -36,18 +36,17 @@ int main(int argc,char * argv[]) rc = mdb_env_open(env, envname, MDB_RDONLY, 0); if (rc) { printf("mdb_env_open failed, error %d\n", rc); - exit(1); + goto env_close; } rc = mdb_txn_begin(env, NULL, 1, &txn); if (rc) { printf("mdb_txn_begin failed, error %d\n", rc); - exit(1); + goto env_close; } rc = mdb_open(txn, subname, 0, &dbi); if (rc) { printf("mdb_open failed, error %d\n", rc); - mdb_txn_abort(txn); - exit(1); + goto txn_abort; } rc = mdb_stat(txn, dbi, &mst); @@ -58,8 +57,10 @@ int main(int argc,char * argv[]) printf("Overflow pages: %zu\n", mst.ms_overflow_pages); printf("Entries: %zu\n", mst.ms_entries); mdb_close(env, dbi); +txn_abort: mdb_txn_abort(txn); +env_close: mdb_env_close(env); - return 0; + return rc ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/libraries/libmdb/mdb_stata.c b/libraries/libmdb/mdb_stata.c index 62f019fe94..f8b2fe59a8 100644 --- a/libraries/libmdb/mdb_stata.c +++ b/libraries/libmdb/mdb_stata.c @@ -34,18 +34,17 @@ int main(int argc,char * argv[]) rc = mdb_env_open(env, envname, MDB_RDONLY, 0); if (rc) { printf("mdb_env_open failed, error %d\n", rc); - exit(1); + goto env_close; } rc = mdb_txn_begin(env, NULL, 1, &txn); if (rc) { printf("mdb_txn_begin failed, error %d\n", rc); - exit(1); + goto env_close; } rc = mdb_open(txn, NULL, 0, &dbi); if (rc) { printf("mdb_open failed, error %d\n", rc); - mdb_txn_abort(txn); - exit(1); + goto txn_abort; } rc = mdb_stat(txn, dbi, &mst); @@ -76,8 +75,10 @@ int main(int argc,char * argv[]) } mdb_cursor_close(cursor); mdb_close(env, dbi); +txn_abort: mdb_txn_abort(txn); +env_close: mdb_env_close(env); - return 0; + return rc ? EXIT_FAILURE : EXIT_SUCCESS; }