diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2020-03-22 00:41:23 +0200 |
---|---|---|
committer | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2020-03-22 00:53:30 +0200 |
commit | ee70e8ce502093bd882a25db0e057993bab72d61 (patch) | |
tree | ca1a2fa283b6bd2518c74f586d7dcfc568ccc68d | |
parent | c4cc48c83dd1404d5cfbdafd81ffbfe265be65d6 (diff) | |
download | mpv-ee70e8ce502093bd882a25db0e057993bab72d61.tar.bz2 mpv-ee70e8ce502093bd882a25db0e057993bab72d61.tar.xz |
js: make wait_event autofree
The VM could throw at pushnode and before mpv_free_node_contents, which
would have resulted in leaked content.
Now this case is handled without leaks.
Note: the lua code still leaks on such case, but mp_lua_PITA doesn't
have destructors like the JS autofree has, which, specifically here,
can do mpv_free_node_contents. So TODO: enhance the lua PITA code to
behave more similar to the JS autofree.
-rw-r--r-- | player/javascript.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/player/javascript.c b/player/javascript.c index 070a63d56a..fedd09b3e5 100644 --- a/player/javascript.c +++ b/player/javascript.c @@ -1084,15 +1084,14 @@ static void makenode(void *ta_ctx, mpv_node *dst, js_State *J, int idx) } // args: wait in secs (infinite if negative) if mpv doesn't send events earlier. -static void script_wait_event(js_State *J) +static void script_wait_event(js_State *J, void *af) { double timeout = js_isnumber(J, 1) ? js_tonumber(J, 1) : -1; mpv_event *event = mpv_wait_event(jclient(J), timeout); - struct mpv_node rn; - mpv_event_to_node(&rn, event); - pushnode(J, &rn); - mpv_free_node_contents(&rn); + mpv_node *rn = new_af_mpv_node(af); + mpv_event_to_node(rn, event); + pushnode(J, rn); } /********************************************************************** @@ -1111,7 +1110,7 @@ struct fn_entry { // FN_ENTRY is a normal js C function, AF_ENTRY is an autofree js C function. static const struct fn_entry main_fns[] = { FN_ENTRY(log, 1), - FN_ENTRY(wait_event, 1), + AF_ENTRY(wait_event, 1), FN_ENTRY(_request_event, 2), AF_ENTRY(find_config_file, 1), FN_ENTRY(command, 1), |