summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-09-23 11:16:50 +0100
committerRichard Hughes <richard@hughsie.com>2015-09-23 11:18:53 +0100
commit09a4ba22a7d5766efcb8eeb674478d69c2e4ba64 (patch)
tree9dd868b14c15fa66d119925e5cf251f05eec495f
parent9ea495176266e92af1710df1ead2d34f77f4b67d (diff)
downloadappstream-glib-09a4ba22a7d5766efcb8eeb674478d69c2e4ba64.tar.gz
Use g_set_object() to fix potential crash when adding pixbufs
-rw-r--r--libappstream-builder/asb-app.c4
-rw-r--r--libappstream-glib/as-icon.c13
-rw-r--r--libappstream-glib/as-image.c8
3 files changed, 7 insertions, 18 deletions
diff --git a/libappstream-builder/asb-app.c b/libappstream-builder/asb-app.c
index 69f8909..3c5a531 100644
--- a/libappstream-builder/asb-app.c
+++ b/libappstream-builder/asb-app.c
@@ -118,9 +118,7 @@ asb_app_set_package (AsbApp *app, AsbPackage *pkg)
{
AsbAppPrivate *priv = GET_PRIVATE (app);
- if (priv->pkg != NULL)
- g_object_unref (priv->pkg);
- priv->pkg = g_object_ref (pkg);
+ g_set_object (&priv->pkg, pkg);
/* be helpful */
if (asb_package_get_kind (pkg) == ASB_PACKAGE_KIND_DEFAULT) {
diff --git a/libappstream-glib/as-icon.c b/libappstream-glib/as-icon.c
index 3afaed8..a23b6ca 100644
--- a/libappstream-glib/as-icon.c
+++ b/libappstream-glib/as-icon.c
@@ -452,16 +452,11 @@ void
as_icon_set_pixbuf (AsIcon *icon, GdkPixbuf *pixbuf)
{
AsIconPrivate *priv = GET_PRIVATE (icon);
-
- if (priv->pixbuf != NULL)
- g_object_unref (priv->pixbuf);
- if (pixbuf == NULL) {
- priv->pixbuf = NULL;
- return;
+ g_set_object (&priv->pixbuf, pixbuf);
+ if (pixbuf != NULL) {
+ priv->width = gdk_pixbuf_get_width (pixbuf);
+ priv->height = gdk_pixbuf_get_height (pixbuf);
}
- priv->pixbuf = g_object_ref (pixbuf);
- priv->width = gdk_pixbuf_get_width (pixbuf);
- priv->height = gdk_pixbuf_get_height (pixbuf);
}
/**
diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c
index 30828b9..ff09339 100644
--- a/libappstream-glib/as-image.c
+++ b/libappstream-glib/as-image.c
@@ -348,18 +348,14 @@ as_image_set_pixbuf (AsImage *image, GdkPixbuf *pixbuf)
guchar *data;
guint len;
- if (priv->pixbuf != NULL)
- g_object_unref (priv->pixbuf);
- if (pixbuf == NULL) {
- priv->pixbuf = NULL;
+ g_set_object (&priv->pixbuf, pixbuf);
+ if (pixbuf == NULL)
return;
- }
if (priv->md5 == NULL) {
data = gdk_pixbuf_get_pixels_with_length (pixbuf, &len);
priv->md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5,
data, len);
}
- priv->pixbuf = g_object_ref (pixbuf);
priv->width = gdk_pixbuf_get_width (pixbuf);
priv->height = gdk_pixbuf_get_height (pixbuf);
}