summaryrefslogtreecommitdiffstats
path: root/player/lua.c
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2022-05-12 16:12:57 +0200
committeravih <avih@users.noreply.github.com>2022-05-12 17:15:37 +0300
commite686297ecf3928b768c674bb10faa6f352b999b8 (patch)
treedec056dd51a73c0fc0a3f85be25bded22a68c9e1 /player/lua.c
parent88120d47599da61e17350da4d35b565d5c3e29aa (diff)
downloadmpv-e686297ecf3928b768c674bb10faa6f352b999b8.tar.bz2
mpv-e686297ecf3928b768c674bb10faa6f352b999b8.tar.xz
lua: avoid rare memory leak in mp.join_path
If lua_pushstring is OOM, then our joined path allocation is leaked. Use autofree to ensure it's not leaked in case of Lua OOM.
Diffstat (limited to 'player/lua.c')
-rw-r--r--player/lua.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/player/lua.c b/player/lua.c
index 665c589802..b3a7167dce 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -1139,13 +1139,12 @@ static int script_split_path(lua_State *L)
return 2;
}
-static int script_join_path(lua_State *L)
+static int script_join_path(lua_State *L, void *tmp)
{
const char *p1 = luaL_checkstring(L, 1);
const char *p2 = luaL_checkstring(L, 2);
- char *r = mp_path_join(NULL, p1, p2);
+ char *r = mp_path_join(tmp, p1, p2);
lua_pushstring(L, r);
- talloc_free(r);
return 1;
}
@@ -1240,7 +1239,7 @@ static const struct fn_entry utils_fns[] = {
AF_ENTRY(readdir),
FN_ENTRY(file_info),
FN_ENTRY(split_path),
- FN_ENTRY(join_path),
+ AF_ENTRY(join_path),
AF_ENTRY(parse_json),
AF_ENTRY(format_json),
FN_ENTRY(get_env_list),