[network-manager-applet] applet: fix pixbuf leak when mobile broadband is connected (lp:939802)



commit 92b09d9ed818ba011018310265bc794dbcf18884
Author: Dan Williams <dcbw redhat com>
Date:   Mon Mar 19 13:44:00 2012 -0500

    applet: fix pixbuf leak when mobile broadband is connected (lp:939802)

 src/applet-device-bt.c    |    2 +-
 src/applet-device-wifi.c  |    2 +-
 src/applet-device-wired.c |    2 +-
 src/applet.c              |   11 ++++++++++-
 src/applet.h              |    4 ++++
 src/mobile-helpers.c      |    1 +
 6 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/src/applet-device-bt.c b/src/applet-device-bt.c
index 76ec74b..4f1cac2 100644
--- a/src/applet-device-bt.c
+++ b/src/applet-device-bt.c
@@ -247,7 +247,7 @@ bt_get_icon (NMDevice *device,
 		break;
 	}
 
-	return pixbuf;
+	return pixbuf ? g_object_ref (pixbuf) : NULL;
 }
 
 typedef struct {
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index f17324c..d674e3b 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -1337,7 +1337,7 @@ wireless_get_icon (NMDevice *device,
 		break;
 	}
 
-	return pixbuf;
+	return pixbuf ? g_object_ref (pixbuf) : NULL;
 }
 
 static gboolean
diff --git a/src/applet-device-wired.c b/src/applet-device-wired.c
index 8cdd02b..ba381f5 100644
--- a/src/applet-device-wired.c
+++ b/src/applet-device-wired.c
@@ -316,7 +316,7 @@ wired_get_icon (NMDevice *device,
 		break;
 	}
 
-	return pixbuf;
+	return pixbuf ? g_object_ref (pixbuf) : NULL;
 }
 
 /* PPPoE */
diff --git a/src/applet.c b/src/applet.c
index 093e158..106e021 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -2523,14 +2523,19 @@ applet_get_device_icon_for_state (NMApplet *applet, char **tip)
 		NMConnection *connection;
 
 		connection = applet_find_active_connection_for_device (device, applet, NULL);
+		/* device class returns a referenced pixbuf */
 		pixbuf = dclass->get_icon (device, state, connection, tip, applet);
 		if (!*tip)
 			*tip = get_tip_for_device_state (device, state, connection);
 	}
 
 out:
-	if (!pixbuf)
+	if (!pixbuf) {
 		pixbuf = applet_common_get_device_icon (state, applet);
+		/* reference the pixbuf to match the device class' get_icon() function behavior */
+		if (pixbuf)
+			g_object_ref (pixbuf);
+	}
 	return pixbuf;
 }
 
@@ -2607,10 +2612,12 @@ applet_update_icon (gpointer user_data)
 	case NM_STATE_UNKNOWN:
 	case NM_STATE_ASLEEP:
 		pixbuf = nma_icon_check_and_load ("nm-no-connection", &applet->no_connection_icon, applet);
+		g_object_ref (pixbuf);
 		dev_tip = g_strdup (_("Networking disabled"));
 		break;
 	case NM_STATE_DISCONNECTED:
 		pixbuf = nma_icon_check_and_load ("nm-no-connection", &applet->no_connection_icon, applet);
+		g_object_ref (pixbuf);
 		dev_tip = g_strdup (_("No network connection"));
 		break;
 	default:
@@ -2619,6 +2626,8 @@ applet_update_icon (gpointer user_data)
 	}
 
 	foo_set_icon (applet, pixbuf, ICON_LAYER_LINK);
+	if (pixbuf)
+		g_object_unref (pixbuf);
 
 	/* VPN state next */
 	pixbuf = NULL;
diff --git a/src/applet.h b/src/applet.h
index ab8fd97..a600aaf 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -228,6 +228,10 @@ struct NMADeviceClass {
 	                                        NMDeviceStateReason reason,
 	                                        NMApplet *applet);
 
+	/* Device class is expected to return a *referenced* pixbuf, which will
+	 * be unrefed by the icon code.  This allows the device class to create
+	 * a composited pixbuf if necessary and pass the reference to the caller.
+	 */
 	GdkPixbuf *    (*get_icon)             (NMDevice *device,
 	                                        NMDeviceState state,
 	                                        NMConnection *connection,
diff --git a/src/mobile-helpers.c b/src/mobile-helpers.c
index bd3e7ea..b6e5635 100644
--- a/src/mobile-helpers.c
+++ b/src/mobile-helpers.c
@@ -79,6 +79,7 @@ mobile_helper_get_status_pixbuf (guint32 quality,
 		}
 	}
 
+	/* 'pixbuf' will be freed by the caller */
 	return pixbuf;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]