lua: emit a proper deletion when setting an existing list to a new list with only...
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 26 May 2013 16:55:20 +0000 (18:55 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 26 May 2013 16:55:20 +0000 (18:55 +0200)
lua/uci.c

index 64e509eb34c0800d8850111bcdfd213ebe8c2750..638290076b391514610b14647f6caf3a9afb9443 100644 (file)
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -551,6 +551,7 @@ uci_lua_set(lua_State *L)
        bool istable = false;
        int err = UCI_ERR_MEM;
        char *s = NULL;
+       const char *v;
        int i, nargs, offset = 0;
 
        ctx = find_context(L, &offset);
@@ -597,8 +598,14 @@ uci_lua_set(lua_State *L)
        if (istable) {
                if (lua_objlen(L, nargs) == 1) {
                        i = 1;
-                       if (ptr.o)
+                       if (ptr.o) {
+                               v = ptr.value;
+                               ptr.value = NULL;
                                err = uci_delete(ctx, &ptr);
+                               if (err)
+                                       goto error;
+                               ptr.value = v;
+                       }
                } else {
                        i = 2;
                        err = uci_set(ctx, &ptr);