Review at  https://gerrit.osmocom.org/5595

mobile: Properly close the primitive interface on reload

When reloading a script go through script_lua_close. Get the
primitive first. Then destruct the lua environment which will
lead to GC (e.g. cancellation of timers) and then delete the
primitive code.

Change-Id: I5bb4fa9e7c5010f3ad50b258dcb14956eea8822a
---
M src/host/layer23/src/mobile/script_lua.c
1 file changed, 6 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/95/5595/1

diff --git a/src/host/layer23/src/mobile/script_lua.c 
b/src/host/layer23/src/mobile/script_lua.c
index 14ab58f..9b256d3 100644
--- a/src/host/layer23/src/mobile/script_lua.c
+++ b/src/host/layer23/src/mobile/script_lua.c
@@ -510,10 +510,14 @@
 
 int script_lua_close(struct osmocom_ms *ms)
 {
+       struct mobile_prim_intf *intf;
+
        if (!ms->lua_state)
                return 0;
 
+       intf = get_primitive(ms->lua_state);
        lua_close(ms->lua_state);
+       mobile_prim_intf_free(intf);
        ms->lua_state = NULL;
        return 0;
 }
@@ -523,8 +527,7 @@
        struct mobile_prim_intf *intf;
        int err;
 
-       if (ms->lua_state)
-               lua_close(ms->lua_state);
+       script_lua_close(ms);
        ms->lua_state = lua_newstate(talloc_lua_alloc, ms);
        if (!ms->lua_state)
                return -1;
@@ -550,7 +553,7 @@
                vty_out(vty, "%% LUA execute error: %s%s",
                                lua_tostring(ms->lua_state, -1), VTY_NEWLINE);
                lua_pop(ms->lua_state, 1);
-               return 3;
+               return -3;
        }
 
        return 0;

-- 
To view, visit https://gerrit.osmocom.org/5595
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5bb4fa9e7c5010f3ad50b258dcb14956eea8822a
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <[email protected]>

Reply via email to