! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Timer leak when docking-undocking laptop
Status:
RESOLVED: FIXED
Product:
Xfdesktop
Component:
General

Comments

Description lehel 2017-09-26 18:08:00 CEST
Timer used for periodic backdrop changes is not freed when monitor is unplugged. After several plug-unplug events timers accumulate resulting in non-periodical backdrop changes with random timing.
Comment 1 lehel 2017-09-26 18:09:06 CEST
Proposed fix:

diff --git a/src/xfce-backdrop.c b/src/xfce-backdrop.c
index 3212586f..31a14e9d 100644
--- a/src/xfce-backdrop.c
+++ b/src/xfce-backdrop.c
@@ -361,6 +361,11 @@ cb_xfce_backdrop_image_files_changed(GFileMonitor     *monitor,
                 backdrop->priv->image_files = g_list_delete_link(backdrop->priv->image_files, item);
 
             g_free(changed_file);
+
+            if (backdrop->priv->cycle_timer_id) {
+                g_source_remove(backdrop->priv->cycle_timer_id);
+                backdrop->priv->cycle_timer_id = 0;
+            }
             break;
         case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
             changed_file = g_file_get_path(file);
@@ -596,10 +601,13 @@ xfce_backdrop_choose_random(XfceBackdrop *backdrop)
         return g_strdup(g_list_first(backdrop->priv->image_files)->data);
     }
Comment 2 lehel 2017-09-26 18:11:51 CEST
Proposed fix (including a bit improved randomness in backdrop selection, as it tends to choose the same set over a period of 20-30 changes):

diff --git a/src/xfce-backdrop.c b/src/xfce-backdrop.c
index 3212586f..31a14e9d 100644
--- a/src/xfce-backdrop.c
+++ b/src/xfce-backdrop.c
@@ -361,6 +361,11 @@ cb_xfce_backdrop_image_files_changed(GFileMonitor     *monitor,
                 backdrop->priv->image_files = g_list_delete_link(backdrop->priv->image_files, item);
 
             g_free(changed_file);
+
+            if (backdrop->priv->cycle_timer_id) {
+                g_source_remove(backdrop->priv->cycle_timer_id);
+                backdrop->priv->cycle_timer_id = 0;
+            }
             break;
         case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
             changed_file = g_file_get_path(file);
@@ -596,10 +601,13 @@ xfce_backdrop_choose_random(XfceBackdrop *backdrop)
         return g_strdup(g_list_first(backdrop->priv->image_files)->data);
     }
 
+    struct GRand *seeder = g_rand_new();
     do {
         /* g_random_int_range bounds to n_items-1 */
-        cur_file = g_random_int_range(0, n_items);
+        cur_file = g_rand_int_range(seeder, 0, n_items);
     } while(cur_file == previndex && G_LIKELY(previndex != -1));
+    g_randr_free(seeder);
+    seeder = 0;
 
     previndex = cur_file;
Comment 3 Skunnyk editbugs 2017-12-03 19:20:48 CET
You should not mix 2 fixes in one patch :)

2 patches here : 
1/ Timer leak when docking-undocking laptop
2/ including a bit improved randomness in backdrop selection, as it tends to choose the same set over a period of 20-30 changes
Comment 4 Git Bot editbugs 2019-05-14 03:37:28 CEST
Andre Miranda referenced this bugreport in commit ffc8740e7ddd576efb51679cd7639535ef217e3d

Avoid timer leak when docking-undocking monitors (Bug #13887)

https://git.xfce.org/xfce/xfdesktop/commit?id=ffc8740e7ddd576efb51679cd7639535ef217e3d
Comment 5 Andre Miranda editbugs 2019-05-14 03:41:37 CEST
Not sure it really leaked, but it seems nothing broke after the patch #1 (please use git format-patch next time).
With regards patch #2, I not convinced it really improves randomness, the documentation is not clear and g_random_int_range just uses a global GRand anyway. Is there any evidence that creating new GRand instances improve randomness? If so please file another bug.
Comment 6 Git Bot editbugs 2019-06-04 21:43:47 CEST
Andre Miranda referenced this bugreport in commit 530102185e953711edf42b6816c5e049c3adad3e

Avoid timer leak when docking-undocking monitors (Bug #13887)

https://git.xfce.org/xfce/xfdesktop/commit?id=530102185e953711edf42b6816c5e049c3adad3e

Bug #13887

Reported by:
lehel
Reported on: 2017-09-26
Last modified on: 2019-06-04

People

Assignee:
Eric Koegel
CC List:
2 users

Version

Version:
4.12.0

Attachments

Additional information