Mir

Merge lp:~albaguirre/mir/fix-1480420 into lp:mir

Proposed by Alberto Aguirre
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 2805
Proposed branch: lp:~albaguirre/mir/fix-1480420
Merge into: lp:mir
Diff against target: 44 lines (+17/-8)
1 file modified
src/server/glib_main_loop_sources.cpp (+17/-8)
To merge this branch: bzr merge lp:~albaguirre/mir/fix-1480420
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Daniel van Vugt Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+266614@code.launchpad.net

Commit message

Avoid calling g_source_get_context when the source is already destroyed.

If the main context has been deleted that marks the source as destroyed.
This may happen in Alarms that outlive the mainloop.

Description of the change

Avoid calling g_source_get_context when the source is already destroyed.

If the main context has been deleted that marks the source as destroyed.
This may happen in Alarms that outlive the mainloop which is the case in some test setups.

This can explain the failure in lp:1480422 as well, as before g_source_get_context could assert leading to FD leaks.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Sounds reasonable.

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Plausible

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/glib_main_loop_sources.cpp'
2--- src/server/glib_main_loop_sources.cpp 2015-06-17 05:20:42 +0000
3+++ src/server/glib_main_loop_sources.cpp 2015-07-31 19:25:59 +0000
4@@ -106,9 +106,9 @@
5 if (gsource)
6 {
7 pre_destruction_hook(gsource);
8+
9+#ifdef GLIB_HAS_FIXED_LP_1401488
10 g_source_destroy(gsource);
11-
12-#ifdef GLIB_HAS_FIXED_LP_1401488
13 g_source_unref(gsource);
14 #else
15 /*
16@@ -118,13 +118,22 @@
17 * and so the main loop might be mid-iteration of the same source
18 * making callbacks. And glib lacks protection to prevent sources
19 * getting fully free()'d mid-callback (TODO: fix glib?). So we defer
20- * the final unref of the source to a point in the loop when it's safe:
21+ * the final unref of the source to a point in the loop when it's safe.
22 */
23- auto main_context = g_source_get_context(gsource);
24- auto idler = g_idle_source_new();
25- g_source_set_callback(idler, idle_callback, gsource, destroy_idler);
26- g_source_attach(idler, main_context);
27- g_source_unref(idler);
28+ if (!g_source_is_destroyed(gsource))
29+ {
30+ auto main_context = g_source_get_context(gsource);
31+ g_source_destroy(gsource);
32+ auto idler = g_idle_source_new();
33+ g_source_set_callback(idler, idle_callback, gsource, destroy_idler);
34+ g_source_attach(idler, main_context);
35+ g_source_unref(idler);
36+ }
37+ else
38+ {
39+ // The source is already destroyed so it's safe to unref now
40+ g_source_unref(gsource);
41+ }
42 #endif
43 }
44 }

Subscribers

People subscribed via source and target branches