summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-07-12 20:57:04 +0300
committerAndrei Karas <akaras@inbox.ru>2017-07-12 20:57:04 +0300
commit17ffc295b10b17f04b4db3cef62bceb2a9768f43 (patch)
tree78fb69c08665d30f9f9b8bbdc2b992dda166753d
parent763069245561fb981e97120f60ca417fd481ebf9 (diff)
downloadevol-hercules-17ffc295b10b17f04b4db3cef62bceb2a9768f43.tar.gz
evol-hercules-17ffc295b10b17f04b4db3cef62bceb2a9768f43.tar.bz2
evol-hercules-17ffc295b10b17f04b4db3cef62bceb2a9768f43.tar.xz
evol-hercules-17ffc295b10b17f04b4db3cef62bceb2a9768f43.zip
Fix crash on exit if any hash iterators was used in scripts.s20170725
Also improve a bit hashtable cleanup code.
-rw-r--r--src/emap/hashtable.c27
1 files 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);
}