Merge lp:~thomir/unity/panelmenuview-fix-invalid-read into lp:unity

Proposed by Thomi Richards on 2012-04-10
Status: Merged
Approved by: Tim Penhey on 2012-04-11
Approved revision: 2265
Merged at revision: 2266
Proposed branch: lp:~thomir/unity/panelmenuview-fix-invalid-read
Merge into: lp:unity
Diff against target: 28 lines (+9/-2)
1 file modified
plugins/unityshell/src/PanelMenuView.cpp (+9/-2)
To merge this branch: bzr merge lp:~thomir/unity/panelmenuview-fix-invalid-read
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve on 2012-04-11
Brandon Schaefer (community) 2012-04-10 Approve on 2012-04-10
Review via email: mp+101452@code.launchpad.net

Commit Message

PanelMenuView no longer tries to dereference a pointer that has already been deleted when it's destroyed.

Description of the Change

Problem:

PanelMenuView has an Animator instance as a member variable. It conntacts the animator's 'animation_finished' signal to PanelMenuView::FullRedraw. When the PanelMenuView dies, the animator calls 'Stop' in it's destructor, which triggers the animation_ended signal (if the animation was running). This in turn calls PanelMenuView::FullRedraw, which tries to access the _window_buttons pointer which has already been deleted. Phew!

Solution:

Explicitly stop the animation in the PanelMenuView destructor BEFORE the _window_buttons member variable is deleted. The Animator class is clever enough not to emit the 'animation_finished' signal if the animation has already been stopped. In order to guard against this happening again in the future, the destructor now sets it's pointer member variables to nullptr after they've been destroyed.

UNBLOCK

To post a comment you must log in.
Brandon Schaefer (brandontschaefer) wrote :

Looks good! +1

review: Approve
Tim Penhey (thumper) wrote :

Please don't assign to nullptr in the destructor. It is pointless.

review: Needs Fixing
2264. By Thomi Richards on 2012-04-11

Found a better way.

2265. By Thomi Richards on 2012-04-11

Removed nullptr assigns.

Tim Penhey (thumper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/PanelMenuView.cpp'
2--- plugins/unityshell/src/PanelMenuView.cpp 2012-04-09 12:35:20 +0000
3+++ plugins/unityshell/src/PanelMenuView.cpp 2012-04-11 00:40:24 +0000
4@@ -173,6 +173,15 @@
5
6 PanelMenuView::~PanelMenuView()
7 {
8+ // We need to disconnect these signals explicitly before we destroy the window buttons
9+ // and titlebar grab area objects, otherwise there's a risk the signals will fire as the
10+ // animator objects are destroyed (which happens after the destructor finishes).
11+ _fade_in_animator.animation_updated.clear();
12+ _fade_in_animator.animation_ended.clear();
13+ _fade_out_animator.animation_updated.clear();
14+ _fade_out_animator.animation_ended.clear();
15+ _style_changed_connection.disconnect();
16+
17 if (_active_moved_id)
18 g_source_remove(_active_moved_id);
19
20@@ -184,8 +193,6 @@
21
22 _window_buttons->UnReference();
23 _titlebar_grab_area->UnReference();
24-
25- _style_changed_connection.disconnect();
26 }
27
28 void PanelMenuView::OverlayShown()