From a110c27ba0e2c189d88a14c2e34f549956d9f09c Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Tue, 15 Apr 2014 21:20:11 +0200 Subject: [PATCH] Fixed g_source_remove call with none existing source. The api was changed and spits out a critical error if a source does no exists. This was the case when the timeout was remove by glib automatically after the timeout function returned false. Now the timeout function does return true to not remove the source automatically, instead the resource is removed by vimb when the timeout is handled in the map_handle_keys function. --- src/map.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/map.c b/src/map.c index 4e6f036..5f538a0 100644 --- a/src/map.c +++ b/src/map.c @@ -169,13 +169,14 @@ MapState map_handle_keys(const guchar *keys, int keylen, gboolean use_map) Map *match = NULL; gboolean timeout = (keylen == 0); /* keylen 0 signalized timeout */ - /* don't set the timeout function if a timeout is handled */ + /* if a previous timeout function was set remove this */ + if (map.timout_id) { + g_source_remove(map.timout_id); + map.timout_id = 0; + } + + /* don't set the timeout function if the timeout is processed now */ if (!timeout) { - /* if a previous timeout function was set remove this to start the - * timeout new */ - if (map.timout_id) { - g_source_remove(map.timout_id); - } map.timout_id = g_timeout_add(vb.config.timeoutlen, (GSourceFunc)do_timeout, NULL); } @@ -575,8 +576,10 @@ static gboolean do_timeout(gpointer data) /* signalize the timeout to the key handler */ map_handle_keys((guchar*)"", 0, true); - /* call only once */ - return false; + /* we return true to not automatically remove the resource - this is + * required to prevent critical error when we remove the source in + * map_handle_keys where we don't know if the timeout was called or not */ + return true; } static void free_map(Map *map) -- 2.20.1