ITS#7369 mdb_stat: cleanup in case something went wrong.

vmware
Ondrej Kuznik 12 years ago committed by Howard Chu
parent a2d1b42e39
commit bd92b570a8
  1. 11
      libraries/libmdb/mdb_stat.c
  2. 11
      libraries/libmdb/mdb_stata.c

@ -36,18 +36,17 @@ int main(int argc,char * argv[])
rc = mdb_env_open(env, envname, MDB_RDONLY, 0); rc = mdb_env_open(env, envname, MDB_RDONLY, 0);
if (rc) { if (rc) {
printf("mdb_env_open failed, error %d\n", rc); printf("mdb_env_open failed, error %d\n", rc);
exit(1); goto env_close;
} }
rc = mdb_txn_begin(env, NULL, 1, &txn); rc = mdb_txn_begin(env, NULL, 1, &txn);
if (rc) { if (rc) {
printf("mdb_txn_begin failed, error %d\n", rc); printf("mdb_txn_begin failed, error %d\n", rc);
exit(1); goto env_close;
} }
rc = mdb_open(txn, subname, 0, &dbi); rc = mdb_open(txn, subname, 0, &dbi);
if (rc) { if (rc) {
printf("mdb_open failed, error %d\n", rc); printf("mdb_open failed, error %d\n", rc);
mdb_txn_abort(txn); goto txn_abort;
exit(1);
} }
rc = mdb_stat(txn, dbi, &mst); 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("Overflow pages: %zu\n", mst.ms_overflow_pages);
printf("Entries: %zu\n", mst.ms_entries); printf("Entries: %zu\n", mst.ms_entries);
mdb_close(env, dbi); mdb_close(env, dbi);
txn_abort:
mdb_txn_abort(txn); mdb_txn_abort(txn);
env_close:
mdb_env_close(env); mdb_env_close(env);
return 0; return rc ? EXIT_FAILURE : EXIT_SUCCESS;
} }

@ -34,18 +34,17 @@ int main(int argc,char * argv[])
rc = mdb_env_open(env, envname, MDB_RDONLY, 0); rc = mdb_env_open(env, envname, MDB_RDONLY, 0);
if (rc) { if (rc) {
printf("mdb_env_open failed, error %d\n", rc); printf("mdb_env_open failed, error %d\n", rc);
exit(1); goto env_close;
} }
rc = mdb_txn_begin(env, NULL, 1, &txn); rc = mdb_txn_begin(env, NULL, 1, &txn);
if (rc) { if (rc) {
printf("mdb_txn_begin failed, error %d\n", rc); printf("mdb_txn_begin failed, error %d\n", rc);
exit(1); goto env_close;
} }
rc = mdb_open(txn, NULL, 0, &dbi); rc = mdb_open(txn, NULL, 0, &dbi);
if (rc) { if (rc) {
printf("mdb_open failed, error %d\n", rc); printf("mdb_open failed, error %d\n", rc);
mdb_txn_abort(txn); goto txn_abort;
exit(1);
} }
rc = mdb_stat(txn, dbi, &mst); rc = mdb_stat(txn, dbi, &mst);
@ -76,8 +75,10 @@ int main(int argc,char * argv[])
} }
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi); mdb_close(env, dbi);
txn_abort:
mdb_txn_abort(txn); mdb_txn_abort(txn);
env_close:
mdb_env_close(env); mdb_env_close(env);
return 0; return rc ? EXIT_FAILURE : EXIT_SUCCESS;
} }

Loading…
Cancel
Save