From 9265acf87945426f765b068dd660995c0e8661f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 13 Apr 2018 19:55:20 +0200 Subject: scripts: fix memory leak in hook_info callback --- src/plugins/lua/weechat-lua-api.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/plugins/lua/weechat-lua-api.c') diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index 8938522e3..1224042de 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -67,6 +67,8 @@ plugin_script_str2ptr (weechat_lua_plugin, \ LUA_CURRENT_SCRIPT_NAME, \ lua_function_name, __string) +#define API_STATIC_STRING(__string) \ + plugin_script_get_static_string(&lua_data, __string); #define API_RETURN_OK \ lua_pushinteger (L, 1); \ return 1 @@ -2994,7 +2996,7 @@ weechat_lua_api_hook_info_cb (const void *pointer, void *data, { struct t_plugin_script *script; void *func_argv[3]; - char empty_arg[1] = { '\0' }; + char empty_arg[1] = { '\0' }, *result; const char *ptr_function, *ptr_data; script = (struct t_plugin_script *)pointer; @@ -3006,10 +3008,12 @@ weechat_lua_api_hook_info_cb (const void *pointer, void *data, func_argv[1] = (info_name) ? (char *)info_name : empty_arg; func_argv[2] = (arguments) ? (char *)arguments : empty_arg; - return (const char *)weechat_lua_exec (script, - WEECHAT_SCRIPT_EXEC_STRING, - ptr_function, - "sss", func_argv); + result = (char *)weechat_lua_exec (script, + WEECHAT_SCRIPT_EXEC_STRING, + ptr_function, + "sss", func_argv); + + return API_STATIC_STRING(result); } return NULL; -- cgit v1.2.3