Prevents a segfault caused by a null filename. This caused frequent but nondeterministic crashes on startup when run on OpenBSD. Buddy icons seem to render fine when this check is added.

Sun, 09 Aug 2015 22:42:34 -0400

author
Michael McConville <mmcconville@mykolab.com>
date
Sun, 09 Aug 2015 22:42:34 -0400
changeset 37228
7e57fa4513f4
parent 37227
17bdb1daf323
child 37229
26514beb9ccb

Prevents a segfault caused by a null filename. This caused frequent but nondeterministic crashes on startup when run on OpenBSD. Buddy icons seem to render fine when this check is added.

libpurple/buddyicon.c file | annotate | diff | comparison | revisions
--- a/libpurple/buddyicon.c	Sun Aug 09 17:09:28 2015 -0400
+++ b/libpurple/buddyicon.c	Sun Aug 09 22:42:34 2015 -0400
@@ -254,16 +254,22 @@
 	newimg = purple_image_new_from_data(icon_data, icon_len);
 	filename = purple_image_generate_filename(newimg);
 
-	oldimg = g_hash_table_lookup(icon_data_cache, filename);
-	if (oldimg) {
-		g_warn_if_fail(PURPLE_IS_IMAGE(oldimg));
-		g_object_unref(newimg);
-		g_object_ref(oldimg);
-		return oldimg;
+	/* TODO: Why is this function called for buddies without icons? If this is
+	 * intended, should the filename be null?
+	 */
+	if (filename != NULL) {
+		oldimg = g_hash_table_lookup(icon_data_cache, filename);
+		if (oldimg) {
+			g_warn_if_fail(PURPLE_IS_IMAGE(oldimg));
+			g_object_unref(newimg);
+			g_object_ref(oldimg);
+			return oldimg;
+		}
+
+		/* This will take ownership of file and free it as needed */
+		g_hash_table_insert(icon_data_cache, g_strdup(filename), newimg);
 	}
 
-	/* This will take ownership of file and free it as needed */
-	g_hash_table_insert(icon_data_cache, g_strdup(filename), newimg);
 	g_object_set_data_full(G_OBJECT(newimg), "purple-buddyicon-filename",
 		g_strdup(filename), image_deleting_cb);
 

mercurial