]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kr_cache_gc: fix double-free for failed/unifinished txns
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 2 Jul 2019 14:11:43 +0000 (16:11 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 10 Jul 2019 13:59:24 +0000 (15:59 +0200)
utils/cache_gc/kr_cache_gc.c
utils/cache_gc/main.c

index e240b2920ea3a932ed98d3f7486cd1a0ef528d6b..b06dd80d4ac81488547ad615e2f22897afed08d5 100644 (file)
@@ -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);
 
index ad249dba0b7ab487d577e0debc173912afe63099..29285e87c1b181c1d2d6e8412440fcf03394c600 100644 (file)
@@ -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;
                }