diff options
author | Tomas Krizek <tomas.krizek@nic.cz> | 2019-07-02 16:11:43 +0200 |
---|---|---|
committer | Petr Špaček <petr.spacek@nic.cz> | 2019-07-10 15:59:24 +0200 |
commit | c7a8849d24be3f3513273240e53f7873abde0c75 (patch) | |
tree | ecf55fd8f668e410e94935015dc04e95dbf3138b /utils | |
parent | gc: better approximation of the space to free (diff) | |
download | knot-resolver-c7a8849d24be3f3513273240e53f7873abde0c75.tar.xz knot-resolver-c7a8849d24be3f3513273240e53f7873abde0c75.zip |
kr_cache_gc: fix double-free for failed/unifinished txns
Diffstat (limited to 'utils')
-rw-r--r-- | utils/cache_gc/kr_cache_gc.c | 12 | ||||
-rw-r--r-- | utils/cache_gc/main.c | 3 |
2 files changed, 9 insertions, 6 deletions
diff --git a/utils/cache_gc/kr_cache_gc.c b/utils/cache_gc/kr_cache_gc.c index e240b292..b06dd80d 100644 --- a/utils/cache_gc/kr_cache_gc.c +++ b/utils/cache_gc/kr_cache_gc.c @@ -249,11 +249,12 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg) already_gone++; break; default: - printf("Warning: skipping deleting because of error (%s)\n", knot_strerror(ret)); + printf("Warning: skipping deletion because of error (%s)\n", knot_strerror(ret)); api->txn_abort(&txn); ret = api->txn_begin(db, &txn, 0); if (ret != KNOT_EOK) { - break; + printf("Error: can't begin txn because of error (%s)\n", knot_strerror(ret)); + goto finish; } continue; } @@ -269,17 +270,18 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg) ret = api->txn_begin(db, &txn, 0); } if (ret != KNOT_EOK) { - break; + printf("Error: transaction failed (%s)\n", knot_strerror(ret)); + goto finish; } } } + ret = api->txn_commit(&txn); +finish: printf("Deleted %zu records (%zu already gone) types", deleted_records, already_gone); rrtypelist_print(&deleted_rrtypes); printf("It took %.2lf secs, %zu transactions (%s)\n", gc_timer_end(&timer_delete), rw_txn_count, knot_strerror(ret)); - ret = api->txn_commit(&txn); - rrtype_dynarray_free(&deleted_rrtypes); entry_dynarray_deep_free(&to_del.to_delete); diff --git a/utils/cache_gc/main.c b/utils/cache_gc/main.c index ad249dba..29285e87 100644 --- a/utils/cache_gc/main.c +++ b/utils/cache_gc/main.c @@ -5,6 +5,7 @@ #include <unistd.h> #include <lib/defines.h> +#include <libknot/libknot.h> #include "kr_cache_gc.h" @@ -118,7 +119,7 @@ int main(int argc, char *argv[]) int ret = kr_cache_gc(&cfg); // ENOENT: kresd may not be started yet or cleared the cache now if (ret && ret != -ENOENT) { - printf("Error (%s)\n", kr_strerror(ret)); + printf("Error (%s)\n", knot_strerror(ret)); return 10; } |