Nux

Merge lp:~vanvugt/nux/fix-769957 into lp:nux

Proposed by Daniel van Vugt
Status: Merged
Merged at revision: 356
Proposed branch: lp:~vanvugt/nux/fix-769957
Merge into: lp:nux
Diff against target: 74 lines (+26/-2)
3 files modified
Nux/Nux.cpp (+1/-1)
Nux/WindowThread.cpp (+23/-1)
Nux/WindowThread.h (+2/-0)
To merge this branch: bzr merge lp:~vanvugt/nux/fix-769957
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Unity Team Pending
Review via email: mp+62641@code.launchpad.net

Commit message

Fix an X11 Display leak, causing window leaks and graphics corruption (LP: #769957)

Description of the change

Fixed an X11 Display leak, which caused Window leaks of the XInputWindows for the Unity panel and launcher. This created graphics corruption each time the Unity plugin restarted (other plugins toggled).

Possibly also fixed other window/resource leaks in nux/unity which were side effects of the same display leak.

Technical notes:

1. The Window objects being leaked are the _window members of XInputWindow used by BaseWindow::m_input_window. While the destructor of XInputWindow does correctly call XDestroyWindow for these, they are still leaked because the DestroyWindow request never reaches the X server. That's because XDestroyWindow only queues the destroy request and does not guarantee it has or will be completed. The display parameter to XDestroyWindow is the display being leaked, and as such never flushes or completes any of its pending requests such as the destroy request.

2. Given technical note #1, it is likely that a simpler workaround for this window leak problem would be to add an XFlush call to the end of XInputWindow::~XInputWindow(). That would be a simpler, more benign and compatible fix for bug 769957, however that would not fix the display leak which is the root cause of the problem. This merge proposal fixes all related leaks by removing the Display leak, which then causes the leaking windows to be destroyed also.

To post a comment you must log in.
Revision history for this message
Jay Taoko (jaytaoko) wrote :

Thank you for your patch! Before we can accept it, we require you to agree to inalogic's contributor agreement (http://inalogic.com/license). If you accept it, send and email to <email address hidden> and state that you agree.

Revision history for this message
Jay Taoko (jaytaoko) wrote :

I am ready to approve the branch. However, is this branch suppose to be an SRU for Unity in Natty? It is based on nux trunk (version 1.0) which is the next version of Nux for Oneiric. Let me know if you submitted this branch as and SRU for Natty and I will port it back to Nux 0.9 series.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Ideally we should backport the fix as much as possible, yes. However there is a problem doing that too quickly. The change to WindowThread.h changes the nux::WindowThread object layout and breaks existing unity binaries. If you can ensure that unity is rebuilt and updated at the same time as the change to nux, then backport away...

Alternatively, my theory above about adding an innocent XFlush to XInputWindow::~XInputWindow() *might* sufficiently solve the bug in question even though it doesn't fix all the leaks. It will *definitely* keep the nux ABI compatible with existing unity releases for natty at least.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Maybe I should test that alternate fix, and we can then recommend only the alternate fix for the 0.9 series if that works?

Revision history for this message
Jay Taoko (jaytaoko) wrote :

Indeed, your branch would break the API of Nux 0.9. However, I will still ask if it can be back ported. Let me know how it goes with the alternate fix.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Confirmed. The XFlush hack alone is enough to fix the corruption bug in natty. Should be compatible with any series:
lp:~vanvugt/nux/fix-769957-natty

Revision history for this message
Jay Taoko (jaytaoko) wrote :

Approved. I am going to merge it into Nux trunk.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/Nux.cpp'
2--- Nux/Nux.cpp 2011-04-06 21:54:09 +0000
3+++ Nux/Nux.cpp 2011-05-27 09:43:27 +0000
4@@ -151,7 +151,7 @@
5 w->m_ExitData = 0;
6 w->SetWindowStyle (WINDOWSTYLE_NORMAL);
7 w->m_embedded_window = true;
8- w->ThreadCtor (XOpenDisplay (NULL), X11Window, OpenGLContext);
9+ w->ThreadCtor (NULL, X11Window, OpenGLContext);
10 return w;
11 }
12 #endif
13
14=== modified file 'Nux/WindowThread.cpp'
15--- Nux/WindowThread.cpp 2011-04-06 21:54:09 +0000
16+++ Nux/WindowThread.cpp 2011-05-27 09:43:27 +0000
17@@ -425,6 +425,10 @@
18 m_GLibLoop = 0;
19 m_GLibContext = 0;
20 #endif
21+#if defined(NUX_OS_LINUX)
22+ _x11display = NULL;
23+ _ownx11display = false;
24+#endif
25
26 _pending_wake_up_timer = false;
27 _inside_main_loop = false;
28@@ -455,6 +459,13 @@
29 delete _Timelines;
30 delete _async_wake_up_functor;
31 delete _fake_event_call_back;
32+
33+#if defined(NUX_OS_LINUX)
34+ if (_x11display && _ownx11display)
35+ {
36+ XCloseDisplay(_x11display);
37+ }
38+#endif
39 }
40
41 void WindowThread::SetFocusedArea (Area *focused_area)
42@@ -1541,7 +1552,18 @@
43 ParentWindow = 0;
44 }
45
46- _graphics_display = gGLWindowManager.CreateFromForeignWindow (X11Display, X11Window, OpenGLContext);
47+ if (X11Display)
48+ {
49+ _x11display = X11Display;
50+ _ownx11display = false;
51+ }
52+ else
53+ {
54+ _x11display = XOpenDisplay(NULL);
55+ _ownx11display = true;
56+ }
57+
58+ _graphics_display = gGLWindowManager.CreateFromForeignWindow (_x11display, X11Window, OpenGLContext);
59
60 if (_graphics_display == 0)
61 {
62
63=== modified file 'Nux/WindowThread.h'
64--- Nux/WindowThread.h 2011-04-06 21:54:09 +0000
65+++ Nux/WindowThread.h 2011-05-27 09:43:27 +0000
66@@ -265,6 +265,8 @@
67
68 */
69 virtual bool ThreadCtor (Display *X11Display, Window X11Window, GLXContext OpenGLContext);
70+ Display *_x11display;
71+ bool _ownx11display;
72 #endif
73
74 /*!

Subscribers

People subscribed via source and target branches