From fae19fa56d110b27bc4f507221573b432cdfc9a8 Mon Sep 17 00:00:00 2001 From: Donald Lee Date: Thu, 8 Jul 2021 01:31:43 +0800 Subject: [PATCH] lib: frrscript unload deallocates Lua function Signed-off-by: Donald Lee --- lib/frrscript.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/frrscript.c b/lib/frrscript.c index 5352c6470d..9b497a431d 100644 --- a/lib/frrscript.c +++ b/lib/frrscript.c @@ -102,6 +102,7 @@ static void codec_free(struct codec *c) } #endif +/* Lua function hash utils */ unsigned int lua_function_hash_key(const void *data) { @@ -129,11 +130,11 @@ void *lua_function_alloc(void *arg) return lfs; } -static void lua_function_free(struct lua_function_state *lfs) +static void lua_function_free(struct hash_bucket *b, void *data) { - XFREE(MTYPE_TMP, lfs->name); + struct lua_function_state *lfs = (struct lua_function_state *)b->data; lua_close(lfs->L); - XFREE(MTYPE_TMP, lfs); + XFREE(MTYPE_SCRIPT, lfs); } /* Generic script APIs */ @@ -313,6 +314,7 @@ fail: void frrscript_unload(struct frrscript *fs) { + hash_iterate(fs->lua_function_hash, lua_function_free, NULL); XFREE(MTYPE_SCRIPT, fs->name); XFREE(MTYPE_SCRIPT, fs); } -- 2.39.5