Fixed g_source_remove call with none existing source.
authorDaniel Carl <danielcarl@gmx.de>
Tue, 15 Apr 2014 19:20:11 +0000 (21:20 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 15 Apr 2014 19:20:41 +0000 (21:20 +0200)
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

index 4e6f036..5f538a0 100644 (file)
--- 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)