Skip to content

Commit c928d97

Browse files
authored
HideTracker: Guard against accessing invalid pointer (#2860)
1 parent afe5632 commit c928d97

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/ShellClients/HideTracker.vala

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Gala.HideTracker : Object {
1414
public signal void show ();
1515

1616
public Meta.Display display { get; construct; }
17-
public unowned PanelWindow panel { get; construct; }
17+
public unowned PanelWindow? panel { get; construct; }
1818

1919
private static GLib.Settings behavior_settings;
2020

@@ -37,6 +37,10 @@ public class Gala.HideTracker : Object {
3737

3838
construct {
3939
panel.window.unmanaging.connect_after (() => {
40+
/* The window was unmanaged so the panel will be freed because we only hold a weak reference,
41+
therefore set it to null to avoid a dangling pointer */
42+
panel = null;
43+
4044
// The timeouts hold refs on us so we stay connected to signal handlers that might
4145
// access the panel which was already freed. To prevent that make sure we reset
4246
// the timeouts so that we get freed immediately
@@ -49,6 +53,10 @@ public class Gala.HideTracker : Object {
4953
unowned var cursor_tracker = display.get_cursor_tracker ();
5054
#endif
5155
cursor_tracker.position_invalidated.connect (() => {
56+
if (panel == null) {
57+
return;
58+
}
59+
5260
var has_pointer = panel.window.has_pointer ();
5361

5462
if (hovered != has_pointer) {
@@ -72,6 +80,10 @@ public class Gala.HideTracker : Object {
7280

7381
private void on_window_created (Meta.Window new_window) {
7482
InternalUtils.wait_for_window_actor (new_window, (new_window_actor) => {
83+
if (panel == null) {
84+
return;
85+
}
86+
7587
if (!panel.window.is_ancestor_of_transient (new_window_actor.meta_window)) {
7688
return;
7789
}
@@ -87,6 +99,10 @@ public class Gala.HideTracker : Object {
8799
}
88100

89101
private void check_trigger_conditions () {
102+
if (panel == null) {
103+
return;
104+
}
105+
90106
if (hovered || has_transients || panel.window.has_focus ()) {
91107
trigger_show ();
92108
} else {
@@ -119,6 +135,10 @@ public class Gala.HideTracker : Object {
119135
}
120136

121137
private void setup_barrier () {
138+
if (panel == null) {
139+
return;
140+
}
141+
122142
var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ());
123143
var scale = Utils.get_ui_scaling_factor (display, display.get_primary_monitor ());
124144
var offset = Utils.scale_to_int (BARRIER_OFFSET, scale);
@@ -174,7 +194,7 @@ public class Gala.HideTracker : Object {
174194

175195
private void on_barrier_triggered () {
176196
// Showing panels in fullscreen is broken in X11
177-
if (InternalUtils.get_x11_in_fullscreen (display)) {
197+
if (InternalUtils.get_x11_in_fullscreen (display) || panel == null) {
178198
return;
179199
}
180200

0 commit comments

Comments
 (0)