summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2019-11-04 23:08:26 +0100
committerPetr Štetiar <ynezz@true.cz>2019-11-14 17:11:34 +0100
commit39093f3b040df895da812e2932b55feeeb1201df (patch)
tree1a4e1442eddc8a22a770cd9b96d9f127b1b98aea /lua
parent19ceff323f1e2e7df26031a9fae29fff2edc65bd (diff)
downloaduci-39093f3b040df895da812e2932b55feeeb1201df.tar.gz
lua: fix memory leak in set method
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>
Diffstat (limited to 'lua')
-rw-r--r--lua/uci.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lua/uci.c b/lua/uci.c
index 42fe4b7..ad08299 100644
--- 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);