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.
Showing the changes to player/javascript.c (1 of 1 file). Show all
Unified · Split
| @@ -1084,15 +1084,14 @@ static void makenode(void *ta_ctx, mpv_node *dst, js_State *J, int idx) · 1083 unmodified lines | |||
| 1084 | } | 1084 | } |
| 1085 | 1085 | ||
| 1086 | // args: wait in secs (infinite if negative) if mpv doesn't send events earlier. | 1086 | // args: wait in secs (infinite if negative) if mpv doesn't send events earlier. |
| 1087 | static void script_wait_event(js_State *J) | 1087 | static void script_wait_event(js_State *J, void *af) |
| 1088 | { | 1088 | { |
| 1089 | double timeout = js_isnumber(J, 1) ? js_tonumber(J, 1) : -1; | 1089 | double timeout = js_isnumber(J, 1) ? js_tonumber(J, 1) : -1; |
| 1090 | mpv_event *event = mpv_wait_event(jclient(J), timeout); | 1090 | mpv_event *event = mpv_wait_event(jclient(J), timeout); |
| 1091 | 1091 | ||
| 1092 | struct mpv_node rn; | 1092 | mpv_node *rn = new_af_mpv_node(af); |
| 1093 | mpv_event_to_node(&rn, event); | 1093 | mpv_event_to_node(rn, event); |
| 1094 | pushnode(J, &rn); | 1094 | pushnode(J, rn); |
| 1095 | mpv_free_node_contents(&rn); | ||
| 1096 | } | 1095 | } |
| 1097 | 1096 | ||
| 1098 | /********************************************************************** | 1097 | /********************************************************************** |
| @@ -1111,7 +1110,7 @@ struct fn_entry { · 12 unmodified lines | |||
| 1111 | // FN_ENTRY is a normal js C function, AF_ENTRY is an autofree js C function. | 1110 | // FN_ENTRY is a normal js C function, AF_ENTRY is an autofree js C function. |
| 1112 | static const struct fn_entry main_fns[] = { | 1111 | static const struct fn_entry main_fns[] = { |
| 1113 | FN_ENTRY(log, 1), | 1112 | FN_ENTRY(log, 1), |
| 1114 | FN_ENTRY(wait_event, 1), | 1113 | AF_ENTRY(wait_event, 1), |
| 1115 | FN_ENTRY(_request_event, 2), | 1114 | FN_ENTRY(_request_event, 2), |
| 1116 | AF_ENTRY(find_config_file, 1), | 1115 | AF_ENTRY(find_config_file, 1), |
| 1117 | FN_ENTRY(command, 1), | 1116 | FN_ENTRY(command, 1), |