From cc5cf98348a2f3675565be65480278ba401ba98a Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 3 Feb 2013 17:43:47 +0100 Subject: input: free all queued/allocated commands on exit These were memory leaks in theory, though not in practice (all memory is free'd on exit anyway). However, it was still annoying when leak reporting is enabled. I'm not sure if there was an actual leak in check_autorepeat(), maybe not. --- core/input/input.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/input/input.c b/core/input/input.c index e5af8e8d0c..06966ce25c 100644 --- a/core/input/input.c +++ b/core/input/input.c @@ -1328,7 +1328,9 @@ static mp_cmd_t *check_autorepeat(struct input_ctx *ictx) unsigned int t = GetTimer(); // First time : wait delay if (ictx->ar_state == 0 - && (t - ictx->last_key_down) >= ictx->ar_delay * 1000) { + && (t - ictx->last_key_down) >= ictx->ar_delay * 1000) + { + talloc_free(ictx->ar_cmd); ictx->ar_cmd = get_cmd_from_keys(ictx, ictx->num_key_down, ictx->key_down); if (!ictx->ar_cmd) { @@ -1519,8 +1521,10 @@ int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd) */ mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int peek_only) { - if (async_quit_request) - return mp_input_parse_cmd(bstr0("quit 1"), ""); + if (async_quit_request) { + struct mp_cmd *cmd = mp_input_parse_cmd(bstr0("quit 1"), ""); + queue_add(&ictx->control_cmd_queue, cmd, true); + } if (ictx->control_cmd_queue.first || ictx->key_cmd_queue.first) time = 0; @@ -1876,6 +1880,15 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf) return ictx; } +static void clear_queue(struct cmd_queue *queue) +{ + while (queue->first) { + struct mp_cmd *item = queue->first; + queue_remove(queue, item); + talloc_free(item); + } +} + void mp_input_uninit(struct input_ctx *ictx) { if (!ictx) @@ -1889,9 +1902,13 @@ void mp_input_uninit(struct input_ctx *ictx) if (ictx->cmd_fds[i].close_func) ictx->cmd_fds[i].close_func(ictx->cmd_fds[i].fd); } - for (int i = 0; i < 2; i++) + for (int i = 0; i < 2; i++) { if (ictx->wakeup_pipe[i] != -1) close(ictx->wakeup_pipe[i]); + } + clear_queue(&ictx->key_cmd_queue); + clear_queue(&ictx->control_cmd_queue); + talloc_free(ictx->ar_cmd); talloc_free(ictx); } -- cgit v1.2.3