lua: fix memory leak in set method
[project/uci.git] / lua / uci.c
index 42fe4b785901cf6f755470f9756a5998a700ca5c..ad082996a3c37f60b038f54cd5fab45d5ac22bd6 100644 (file)
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -620,8 +620,10 @@ uci_lua_set(lua_State *L)
        case 4:
                /* Format: uci.set("p", "s", "o", "v") */
                if (lua_istable(L, nargs)) {
-                       if (lua_rawlen(L, nargs) < 1)
+                       if (lua_rawlen(L, nargs) < 1) {
+                               free(s);
                                return luaL_error(L, "Cannot set an uci option to an empty table value");
+                       }
                        lua_rawgeti(L, nargs, 1);
                        ptr.value = luaL_checkstring(L, -1);
                        lua_pop(L, 1);