scan-build from clang version 9 has reported following issue:
uci.c:624:12: warning: Potential leak of memory pointed to by 's'
return luaL_error(L, "Cannot set an uci option to an empty table value");
^~~~~~~~~~
valgrind confirmed it on the supplied test case:
==31013== 8 bytes in 1 blocks are definitely lost in loss record 1 of 1
==31013== by 0x56C49B9: strdup (strdup.c:42)
Signed-off-by: Petr Štetiar <ynezz@true.cz>
case 4:
/* Format: uci.set("p", "s", "o", "v") */
if (lua_istable(L, nargs)) {
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");
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);
lua_rawgeti(L, nargs, 1);
ptr.value = luaL_checkstring(L, -1);
lua_pop(L, 1);
--- /dev/null
+local c = uci.cursor(os.getenv("CONFIG_DIR"))
+print(pcall(c.set, c, "network", "lan", "dns", {}))
$ cp -R "$TESTDIR/config" .
$ export CONFIG_DIR=$(pwd)/config
$ ucilua $TESTDIR/lua/test_cases/changes_doesnt_leak.lua
$ cp -R "$TESTDIR/config" .
$ export CONFIG_DIR=$(pwd)/config
$ ucilua $TESTDIR/lua/test_cases/changes_doesnt_leak.lua
+
+check that set method with empty table value doesn't leak memory:
+
+ $ cp -R "$TESTDIR/config" .
+ $ export CONFIG_DIR=$(pwd)/config
+ $ ucilua $TESTDIR/lua/test_cases/set_with_empty_table_doesnt_leak.lua
+ false\tCannot set an uci option to an empty table value (esc)