Merge lp:~muktupavels/indicator-applet/memory-leaks into lp:indicator-applet

Proposed by Alberts Muktupāvels on 2020-03-29
Status: Merged
Approved by: Dmitry Shachnev on 2020-03-29
Approved revision: 446
Merged at revision: 445
Proposed branch: lp:~muktupavels/indicator-applet/memory-leaks
Merge into: lp:indicator-applet
Diff against target: 129 lines (+46/-3)
1 file modified
src/indicator-applet.c (+46/-3)
To merge this branch: bzr merge lp:~muktupavels/indicator-applet/memory-leaks
Reviewer Review Type Date Requested Status
Dmitry Shachnev 2020-03-29 Pending
Review via email: mp+381352@code.launchpad.net

Commit message

Fix memory leaks.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator-applet.c'
2--- src/indicator-applet.c 2020-03-22 12:39:10 +0000
3+++ src/indicator-applet.c 2020-03-29 15:20:40 +0000
4@@ -63,6 +63,8 @@
5 typedef struct
6 {
7 GtkWidget *menubar;
8+ GList *indicators;
9+ gboolean in_dispose;
10 } IndicatorAppletPrivate;
11
12 G_DEFINE_TYPE_WITH_PRIVATE (IndicatorApplet, indicator_applet, GP_TYPE_APPLET)
13@@ -357,12 +359,21 @@
14 IndicatorObjectEntry *entry,
15 IndicatorApplet *self)
16 {
17+ IndicatorAppletPrivate *priv;
18 const gchar * name;
19 GtkWidget * menuitem;
20 GHashTable * menuitem_lookup;
21 gboolean something_visible;
22 gboolean something_sensitive;
23
24+ priv = indicator_applet_get_instance_private (self);
25+
26+ /* IndicatorObject emits entry-added signal for all IndicatorObjectEntry
27+ * if they are not already visible in dispose.
28+ */
29+ if (priv->in_dispose)
30+ return;
31+
32 name = g_object_get_data (G_OBJECT(io), IO_DATA_NAME);
33 g_debug ("Signal: Entry Added from %s", name);
34
35@@ -592,7 +603,10 @@
36 load_module (const char *name,
37 IndicatorApplet *self)
38 {
39-
40+ IndicatorAppletPrivate *priv;
41+
42+ priv = indicator_applet_get_instance_private (self);
43+
44 g_debug("Looking at Module: %s", name);
45 g_return_val_if_fail(name != NULL, FALSE);
46
47@@ -607,6 +621,8 @@
48 IndicatorObject * io = indicator_object_new_from_file(fullpath);
49 g_free(fullpath);
50
51+ priv->indicators = g_list_prepend (priv->indicators, io);
52+
53 load_indicator (self, io, name);
54
55 return TRUE;
56@@ -642,10 +658,13 @@
57 load_indicators_from_indicator_files (IndicatorApplet *self,
58 int *indicators_loaded)
59 {
60+ IndicatorAppletPrivate *priv;
61 GDir *dir;
62 const gchar *name;
63 GError *error = NULL;
64
65+ priv = indicator_applet_get_instance_private (self);
66+
67 dir = g_dir_open (INDICATOR_SERVICE_DIR, 0, &error);
68
69 if (!dir) {
70@@ -660,12 +679,14 @@
71 gchar *filename;
72 IndicatorNg *indicator;
73
74+ if (!INDICATOR_APPLET_GET_CLASS (self)->load_indicator (name))
75+ continue;
76+
77 filename = g_build_filename (INDICATOR_SERVICE_DIR, name, NULL);
78 indicator = indicator_ng_new_for_profile (filename, "desktop", &error);
79 g_free (filename);
80
81- if (!INDICATOR_APPLET_GET_CLASS (self)->load_indicator (name))
82- continue;
83+ priv->indicators = g_list_prepend (priv->indicators, indicator);
84
85 if (indicator) {
86 g_debug ("loading indicator: %s", name);
87@@ -781,6 +802,7 @@
88 gtk_label_set_angle(GTK_LABEL(item), get_label_angle (swap_data->self));
89 }
90 gtk_box_pack_start(GTK_BOX(to), item, FALSE, FALSE, 0);
91+ g_object_unref(G_OBJECT(item));
92 }
93
94 static void
95@@ -913,6 +935,26 @@
96 indicator_applet_setup (INDICATOR_APPLET (object));
97 }
98
99+static void
100+indicator_applet_dispose (GObject *object)
101+{
102+ IndicatorApplet *self;
103+ IndicatorAppletPrivate *priv;
104+
105+ self = INDICATOR_APPLET (object);
106+ priv = indicator_applet_get_instance_private (self);
107+
108+ priv->in_dispose = TRUE;
109+
110+ if (priv->indicators != NULL)
111+ {
112+ g_list_free_full (priv->indicators, g_object_unref);
113+ priv->indicators = NULL;
114+ }
115+
116+ G_OBJECT_CLASS (indicator_applet_parent_class)->dispose (object);
117+}
118+
119 static const char *
120 indicator_applet_get_name (void)
121 {
122@@ -975,6 +1017,7 @@
123 object_class = G_OBJECT_CLASS (self_class);
124
125 object_class->constructed = indicator_applet_constructed;
126+ object_class->dispose = indicator_applet_dispose;
127
128 self_class->get_name = indicator_applet_get_name;
129 self_class->get_description = indicator_applet_get_description;

Subscribers

People subscribed via source and target branches