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.
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); }
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;
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
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
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.
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