lua: fix memory leak in changes method
[project/uci.git] / lua / uci.c
index 323f81a68c17882e33a33455603153d989f18093..42fe4b785901cf6f755470f9756a5998a700ca5c 100644 (file)
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -880,16 +880,17 @@ uci_lua_changes(lua_State *L)
        lua_newtable(L);
        if (package) {
                uci_lua_changes_pkg(L, ctx, package);
-       } else {
-               if (uci_list_configs(ctx, &config) != 0)
-                       goto done;
+               return 1;
+       }
 
-               for(i = 0; config[i] != NULL; i++) {
-                       uci_lua_changes_pkg(L, ctx, config[i]);
-               }
+       if ((uci_list_configs(ctx, &config) != UCI_OK) || !config)
+               return 1;
+
+       for (i = 0; config[i] != NULL; i++) {
+               uci_lua_changes_pkg(L, ctx, config[i]);
        }
 
-done:
+       free(config);
        return 1;
 }