changeset 20150:52dce2882c03

Fix a few memory leaks in #3281 (details in ticket).
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 23 Sep 2007 20:34:35 +0000
parents be2538a92099
children b8962a8c5daa
files libpurple/protocols/myspace/markup.c libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/user.c
diffstat 3 files changed, 35 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/markup.c	Sun Sep 23 20:30:57 2007 +0000
+++ b/libpurple/protocols/myspace/markup.c	Sun Sep 23 20:34:35 2007 +0000
@@ -515,7 +515,8 @@
 #endif
 
 		err = g_strdup_printf("html_tag_to_msim_markup: unrecognized "
-			"HTML tag %s was sent by the IM client; ignoring");
+			"HTML tag %s was sent by the IM client; ignoring", 
+			root->name ? root->name : "(NULL)");
 		msim_unrecognized(NULL, NULL, err);
 		g_free(err);
 	}
--- a/libpurple/protocols/myspace/myspace.c	Sun Sep 23 20:30:57 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sun Sep 23 20:34:35 2007 +0000
@@ -453,6 +453,7 @@
 	purple_cipher_context_append(key_context, hash_pw, HASH_SIZE);
 	purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE);
 	purple_cipher_context_digest(key_context, sizeof(key), key, NULL);
+	purple_cipher_context_destroy(key_context);
 
 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
 	purple_debug_info("msim", "key = ");
@@ -1029,7 +1030,7 @@
 	PurpleStatusType *type;
 	MsimSession *session;
 	guint status_code;
-	const gchar *statstring;
+	gchar *statstring;
 
 	session = (MsimSession *)account->gc->proto_data;
 
@@ -1063,7 +1064,7 @@
 			break;
 	}
 
-	statstring = purple_status_get_attr_string(status, "message");
+	statstring = (gchar *)purple_status_get_attr_string(status, "message");
 
 	if (!statstring) {
 		statstring = "";
@@ -1072,7 +1073,7 @@
 	/* Status strings are plain text. */
 	statstring = purple_markup_strip_html(statstring);
 
-	msim_set_status_code(session, status_code, g_strdup(statstring));
+	msim_set_status_code(session, status_code, statstring);
 }
 
 /** Go idle. */
@@ -1203,7 +1204,7 @@
 		if (uid == wanted_uid)
 		{
 			ret = g_strdup(name);
-            break;
+			break;
 		}
 	}
 
@@ -1860,6 +1861,7 @@
 		purple_blist_add_buddy(buddy, NULL, NULL, NULL);
 
 		user = msim_get_user_from_buddy(buddy);
+		/* TODO: free user. memory leak? */
 
 		/* All buddies on list should have 'uid' integer associated with them. */
 		purple_blist_node_set_int(&buddy->node, "UserID", msim_msg_get_integer(msg, "f"));
--- a/libpurple/protocols/myspace/user.c	Sun Sep 23 20:30:57 2007 +0000
+++ b/libpurple/protocols/myspace/user.c	Sun Sep 23 20:34:35 2007 +0000
@@ -154,7 +154,13 @@
 	}
 }
 
-/** Store a field of information about a buddy. */
+/** Store a field of information about a buddy. 
+ *
+ * @param key_str Key to store.
+ * @param value_str Value string, either user takes ownership of this string
+ *                  or it is freed if MsimUser doesn't store the string.
+ * @param user User to store data in. Existing data will be replaced.
+ * */
 void 
 msim_store_user_info_each(const gchar *key_str, gchar *value_str, MsimUser *user)
 {
@@ -168,25 +174,33 @@
 		/* Need to store in MsimUser, too? What if not on blist? */
 	} else if (g_str_equal(key_str, "Age")) {
 		user->age = atol(value_str);
+		g_free(value_str);
 	} else if (g_str_equal(key_str, "Gender")) {
-		user->gender = g_strdup(value_str);
+		g_free(user->gender);
+		user->gender = value_str;
 	} else if (g_str_equal(key_str, "Location")) {
-		user->location = g_strdup(value_str);
+		g_free(user->location);
+		user->location = value_str;
 	} else if (g_str_equal(key_str, "TotalFriends")) {
 		user->total_friends = atol(value_str);
 	} else if (g_str_equal(key_str, "DisplayName")) {
-		user->display_name = g_strdup(value_str);
+		g_free(user->display_name);
+		user->display_name = value_str;
 	} else if (g_str_equal(key_str, "BandName")) {
-		user->band_name = g_strdup(value_str);
+		g_free(user->band_name);
+		user->band_name = value_str;
 	} else if (g_str_equal(key_str, "SongName")) {
-		user->song_name = g_strdup(value_str);
+		g_free(user->song_name);
+		user->song_name = value_str;
 	} else if (g_str_equal(key_str, "UserName") || g_str_equal(key_str, "IMName") || g_str_equal(key_str, "NickName")) {
 		/* Ignore because PurpleBuddy knows this already */
-		;
+		g_free(value_str);
 	} else if (g_str_equal(key_str, "ImageURL") || g_str_equal(key_str, "AvatarURL")) {
 		const gchar *previous_url;
 
-		user->image_url = g_strdup(value_str);
+		g_free(user->image_url);
+
+		user->image_url = value_str;
 
 		/* Instead of showing 'no photo' picture, show nothing. */
 		if (g_str_equal(user->image_url, "http://x.myspace.com/images/no_pic.gif"))
@@ -207,14 +221,17 @@
 	} else if (g_str_equal(key_str, "LastImageUpdated")) {
 		/* TODO: use somewhere */
 		user->last_image_updated = atol(value_str);
+		g_free(value_str);
 	} else if (g_str_equal(key_str, "Headline")) {
-		user->headline = g_strdup(value_str);
+		g_free(user->headline);
+		user->headline = value_str;
 	} else {
 		/* TODO: other fields in MsimUser */
 		gchar *msg;
 
 		msg = g_strdup_printf("msim_store_user_info_each: unknown field %s=%s",
 				key_str, value_str);
+		g_free(value_str);
 
 		msim_unrecognized(NULL, NULL, msg);
 
@@ -284,7 +301,6 @@
 
 		value_str = msim_msg_get_string_from_element(elem);
 		msim_store_user_info_each(key_str, value_str, user);
-		g_free(value_str);
 	}
 
 	if (msim_msg_get_integer(msg, "dsn") == MG_OWN_IM_INFO_DSN &&
@@ -301,6 +317,7 @@
 	}
 
 	msim_msg_free(body);
+	g_free(username);
 
 	return TRUE;
 }