Merge lp:~unity-team/unity/unity-sru-fix-mem-leaks into lp:unity/3.0

Proposed by Jay Taoko
Status: Merged
Approved by: Neil J. Patel
Approved revision: no longer in the source branch.
Merged at revision: 1198
Proposed branch: lp:~unity-team/unity/unity-sru-fix-mem-leaks
Merge into: lp:unity/3.0
Diff against target: 51 lines (+11/-2)
2 files modified
src/PanelMenuView.cpp (+5/-1)
src/unityshell.cpp (+6/-1)
To merge this branch: bzr merge lp:~unity-team/unity/unity-sru-fix-mem-leaks
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Daniel van Vugt Needs Fixing
Review via email: mp+62927@code.launchpad.net

Description of the change

* _window_buttons was not properly destroyed in PanelMenuView::~PanelMenuView, resulting in a memory leak.
* In UnityScreen::initLauncher, self->launcherWindow and self->launcher where no properly reference counted.
* In UnityScreen::~UnityScreen, do not call layout->UnReference (). The layout is managed and freed by its parent widget (Unless SinkReference was called on the layout before it was added in the widget tree).

To post a comment you must log in.
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Those changes to unityshell.cpp are similar to what I had implemented and was going to move into a new bug at some point.

Two concerns though:

1. layout should now be a local variable, because it is effectively lost to the UnityScreen class once it is assigned to the launcherWindow. The layout member should then be removed completely. Alternatively, if you keep layout as a member then a more clear and elegant solution is to reintroduce its UnReference and just give it a SinkReference too.

2. My fixes to unityshell.cpp also have this leak-fix you seem to be missing:

   LOGGER_START_PROCESS ("initLauncher-Panel");
   self->panelController = new PanelController ();
+ self->panelController->SinkReference();
   self->AddChild (self->panelController);
   LOGGER_END_PROCESS ("initLauncher-Panel");

Maybe I was mistaken?...

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

See also similar fixes are required for PanelController:
http://bazaar.launchpad.net/~vanvugt/+junk/unity/revision/87#src/PanelController.cpp

I know there are more such leaks to fix but never bothered committing the fixes. It really should be an exercise it ticking off a list of valgrind results in a new bug later on.

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

Needs fixing as described above.

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

1. We could remove the layout member variable if it is not a problem for the SRU (change in the .h file)
2. You don't need to call SinkReference on the panelController because it does not have a floating reference. Only objects that inherit from Nux::InitiallyUnownedObject have a floating reference. In Nux, widgets (see Nux::Area) have a floating reference. Calling SinkReference on panelController will do nothing.

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

I believe it is safe to change unityshell.h because it is not exported in an SDK or seen by any other packages.

Revision history for this message
Neil J. Patel (njpatel) wrote :

Approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/PanelMenuView.cpp'
2--- src/PanelMenuView.cpp 2011-04-14 13:19:11 +0000
3+++ src/PanelMenuView.cpp 2011-05-30 22:25:57 +0000
4@@ -168,7 +168,11 @@
5 _title_tex->UnReference ();
6
7 _menu_layout->UnReference ();
8- _window_buttons->UnReference ();
9+ if (_window_buttons->OwnsTheReference ())
10+ _window_buttons->UnReference ();
11+ else
12+ _window_buttons->Dispose ();
13+
14 _panel_titlebar_grab_area->UnReference ();
15
16 UBusServer* ubus = ubus_server_get_default ();
17
18=== modified file 'src/unityshell.cpp'
19--- src/unityshell.cpp 2011-05-26 15:28:38 +0000
20+++ src/unityshell.cpp 2011-05-30 22:25:57 +0000
21@@ -988,7 +988,6 @@
22 delete placesController;
23 panelController->UnReference ();
24 delete controller;
25- layout->UnReference ();
26 launcher->UnReference ();
27 launcherWindow->UnReference ();
28
29@@ -1016,9 +1015,14 @@
30
31 LOGGER_START_PROCESS ("initLauncher-Launcher");
32 self->launcherWindow = new nux::BaseWindow(TEXT("LauncherWindow"));
33+ self->launcherWindow->SinkReference ();
34+
35 self->launcher = new Launcher(self->launcherWindow, self->screen);
36+ self->launcher->SinkReference ();
37+
38 self->launcher->hidden_changed.connect (sigc::mem_fun (self, &UnityScreen::OnLauncherHiddenChanged));
39
40+
41 self->AddChild (self->launcher);
42
43 self->layout = new nux::HLayout();
44@@ -1035,6 +1039,7 @@
45 self->launcherWindow->ShowWindow(true);
46 self->launcherWindow->EnableInputWindow(true, "launcher", false, false);
47 self->launcherWindow->InputWindowEnableStruts(true);
48+
49 self->launcherWindow->SetEnterFocusInputArea (self->launcher);
50
51 /* FIXME: this should not be manual, should be managed with a

Subscribers

People subscribed via source and target branches

to all changes: