It was pretty confusing when reading/reviewing code.
g_free (new_format_name);
- /* Takes ownership of new_mime_type and best_image_data */
avatar = empathy_avatar_new ((guchar *) best_image_data,
best_image_size, new_mime_type, NULL);
+ g_free (best_image_data);
+ g_free (new_mime_type);
+
return avatar;
}
g_object_unref (pixbuf);
}
+/* takes ownership of @data */
static void
avatar_chooser_set_image_from_data (EmpathyAvatarChooser *self,
gchar *data,
return;
}
- /* avatar takes ownership of data and mime_type */
avatar = empathy_avatar_new ((guchar *) data, size, mime_type, NULL);
avatar_chooser_set_image (self, avatar, pixbuf, set_locally);
+
+ g_free (mime_type);
+ g_free (data);
}
static void
if (handled)
{
- /* this in turn calls empathy_avatar_new (), which assumes
- * ownership of data.
- */
- avatar_chooser_set_image_from_data (self, data,
- bytes_read,
- TRUE);
+ /* pass data to the avatar_chooser_set_image_from_data */
+ avatar_chooser_set_image_from_data (self, data, bytes_read, TRUE);
}
g_object_unref (file);
return;
}
+ /* pass image_data to the avatar_chooser_set_image_from_data */
avatar_chooser_set_image_from_data (self, image_data, image_size, TRUE);
}
avatar_chooser_set_avatar_from_pixbuf (EmpathyAvatarChooser *self,
GdkPixbuf *pb)
{
- /* dup the string as empathy_avatar_new steals ownership of the it */
- gchar *mime = g_strdup ("image/png");
gsize size;
gchar *buf;
EmpathyAvatar *avatar = NULL;
return;
}
- avatar = empathy_avatar_new ((guchar *) buf, size, mime, NULL);
+ avatar = empathy_avatar_new ((guchar *) buf, size, "image/png", NULL);
avatar_chooser_set_image (self, avatar, pb, TRUE);
+
+ g_free (buf);
}
static gboolean
}
}
- 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;
}
* @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;
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
{
#define EMPATHY_TYPE_AVATAR (empathy_avatar_get_type ())
GType empathy_avatar_get_type (void) G_GNUC_CONST;
-EmpathyAvatar * empathy_avatar_new (guchar *data,
+EmpathyAvatar * empathy_avatar_new (const guchar *data,
gsize len,
- gchar *format,
- gchar *filename);
+ const gchar *format,
+ const gchar *filename);
EmpathyAvatar * empathy_avatar_ref (EmpathyAvatar *avatar);
void empathy_avatar_unref (EmpathyAvatar *avatar);