From 17ffc295b10b17f04b4db3cef62bceb2a9768f43 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 12 Jul 2017 20:57:04 +0300 Subject: Fix crash on exit if any hash iterators was used in scripts. Also improve a bit hashtable cleanup code. --- src/emap/hashtable.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/emap/hashtable.c b/src/emap/hashtable.c index 9d2908d..6645a0d 100644 --- a/src/emap/hashtable.c +++ b/src/emap/hashtable.c @@ -117,6 +117,7 @@ bool htreg_destroy_iterator(int64 id) if (it) { dbi_destroy(it); + i64db_remove(htreg->iterators, id); return true; } return false; @@ -160,23 +161,29 @@ void htreg_init(void) */ void htreg_final(void) { - struct DBIterator *iter = db_iterator(htreg->htables); - struct DBMap *ht; - for(ht=dbi_first(iter); dbi_exists(iter); ht=dbi_next(iter)) - db_destroy(ht); + if (htreg->htables != NULL) + { + struct DBMap *ht; + struct DBIterator *iter = db_iterator(htreg->htables); + for (ht = dbi_first(iter); dbi_exists(iter); ht = dbi_next(iter)) + db_destroy(ht); - dbi_destroy(iter); + dbi_destroy(iter); + } db_destroy(htreg->htables); // NOTE: maybe I should destroy iteratos before hashtables - struct DBIterator *it; - iter = db_iterator(htreg->iterators); - for (it=dbi_first(iter); dbi_exists(iter); it=dbi_next(iter)) - dbi_destroy(it); + if (htreg->iterators != NULL) + { + struct DBIterator *it; + struct DBIterator *iter = db_iterator(htreg->iterators); + for (it = dbi_first(iter); dbi_exists(iter); it = dbi_next(iter)) + dbi_destroy(it); - dbi_destroy(iter); + dbi_destroy(iter); + } db_destroy(htreg->iterators); } -- cgit v1.2.3-60-g2f50