aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-contact.c
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-05-26 17:10:06 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-06-01 17:58:09 +0800
commit7625bd2ae11f2c3064e3e208ea82fffa97dc7f18 (patch)
treea712a30e71d5f2fd97f4047a35f8078f5b4ecb9e /libempathy/empathy-contact.c
parentba731f3dceb447ffe8c4b9e168ad1c1a5f99f365 (diff)
downloadgsoc2013-empathy-7625bd2ae11f2c3064e3e208ea82fffa97dc7f18.tar
gsoc2013-empathy-7625bd2ae11f2c3064e3e208ea82fffa97dc7f18.tar.gz
gsoc2013-empathy-7625bd2ae11f2c3064e3e208ea82fffa97dc7f18.tar.bz2
gsoc2013-empathy-7625bd2ae11f2c3064e3e208ea82fffa97dc7f18.tar.lz
gsoc2013-empathy-7625bd2ae11f2c3064e3e208ea82fffa97dc7f18.tar.xz
gsoc2013-empathy-7625bd2ae11f2c3064e3e208ea82fffa97dc7f18.tar.zst
gsoc2013-empathy-7625bd2ae11f2c3064e3e208ea82fffa97dc7f18.zip
empathy_avatar_new: stop stealing strings (#650939)
It was pretty confusing when reading/reviewing code.
Diffstat (limited to 'libempathy/empathy-contact.c')
-rw-r--r--libempathy/empathy-contact.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index f3e200e27..7b23df0fc 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -1282,17 +1282,16 @@ contact_load_avatar_cache (EmpathyContact *contact,
}
}
- if (data)
+ if (data != NULL)
{
DEBUG ("Avatar loaded from %s", filename);
avatar = empathy_avatar_new ((guchar *) data, len, NULL, filename);
contact_set_avatar (contact, avatar);
empathy_avatar_unref (avatar);
}
- else
- {
- g_free (filename);
- }
+
+ g_free (data);
+ g_free (filename);
return data != NULL;
}
@@ -1319,24 +1318,23 @@ empathy_avatar_get_type (void)
* @format: the mime type of the avatar image
* @filename: the filename where the avatar is stored in cache
*
- * Create a #EmpathyAvatar from the provided data. This function takes the
- * ownership of @data, @format and @filename.
+ * Create a #EmpathyAvatar from the provided data.
*
* Returns: a new #EmpathyAvatar
*/
EmpathyAvatar *
-empathy_avatar_new (guchar *data,
+empathy_avatar_new (const guchar *data,
gsize len,
- gchar *format,
- gchar *filename)
+ const gchar *format,
+ const gchar *filename)
{
EmpathyAvatar *avatar;
avatar = g_slice_new0 (EmpathyAvatar);
- avatar->data = data;
+ avatar->data = g_memdup (data, len);
avatar->len = len;
- avatar->format = format;
- avatar->filename = filename;
+ avatar->format = g_strdup (format);
+ avatar->filename = g_strdup (filename);
avatar->refcount = 1;
return avatar;
@@ -1783,12 +1781,17 @@ contact_set_avatar_from_tp_contact (EmpathyContact *contact)
EmpathyAvatar *avatar;
gchar *data;
gsize len;
+ gchar *path;
g_file_load_contents (file, NULL, &data, &len, NULL, NULL);
- avatar = empathy_avatar_new ((guchar *) data, len, g_strdup (mime),
- g_file_get_path (file));
+ path = g_file_get_path (file);
+
+ avatar = empathy_avatar_new ((guchar *) data, len, mime, path);
+
contact_set_avatar (contact, avatar);
empathy_avatar_unref (avatar);
+ g_free (path);
+ g_free (data);
}
else
{