changeset 20753:61045691aa72

Fix a few more memory leaks. Someone who has a myspace account should stare at the code and fix leaks.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 02 Oct 2007 06:13:27 +0000
parents e92c9987ba0d
children 18cf8aa44f55 09300c787a88 9c226e074462
files libpurple/protocols/myspace/markup.c libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/user.c
diffstat 3 files changed, 38 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/markup.c	Tue Oct 02 04:38:10 2007 +0000
+++ b/libpurple/protocols/myspace/markup.c	Tue Oct 02 06:13:27 2007 +0000
@@ -570,10 +570,7 @@
 	
 		case XMLNODE_TYPE_DATA:
 			/* Literal text. */
-			inner = g_new0(char, node->data_sz + 1);
-			strncpy(inner, node->data, node->data_sz);
-			inner[node->data_sz] = 0;
-
+			inner = g_strndup(node->data, node->data_sz);
 			purple_debug_info("msim", " ** node data=%s\n", 
 					inner ? inner : "(NULL)");
 			break;
@@ -586,6 +583,8 @@
 
 		if (inner) {
 			g_string_append(final, inner);
+			g_free(inner);
+			inner = NULL;
 		}
 	}
 
@@ -595,6 +594,9 @@
 	 * Comment out this line below to see. */
 	g_string_append(final, end);
 
+	g_free(begin);
+	g_free(end);
+
 	purple_debug_info("msim", "msim_markup_xmlnode_to_gtkhtml: RETURNING %s\n",
 			(final && final->str) ? final->str : "(NULL)");
 
--- a/libpurple/protocols/myspace/myspace.c	Tue Oct 02 04:38:10 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Tue Oct 02 06:13:27 2007 +0000
@@ -289,7 +289,7 @@
 				(int)strlen(acct->password));
 
 		/* Notify an error message also, because this is important! */
-		purple_notify_error(acct, g_strdup(_("MySpaceIM Error")), str, NULL);
+		purple_notify_error(acct, _("MySpaceIM Error"), str, NULL);
 
 		gc->wants_to_die = TRUE;
 		purple_connection_error(gc, str);
@@ -636,6 +636,7 @@
 	g_return_val_if_fail(username != NULL, FALSE);
 	if (!cv) {
 		/* No client version to record, don't worry about it. */
+		g_free(username);
 		return FALSE;
 	}
 
@@ -825,6 +826,7 @@
 	serv_got_typing_stopped(session->gc, username);
 
 	g_free(username);
+	g_free(text);
 
 	return TRUE;
 }
@@ -973,7 +975,6 @@
 	purple_debug_info("msim", "msim_get_info_cb: username=%s\n", username);
 
 	purple_notify_user_info_destroy(user_info);
-	/* TODO: do not free username, since it will be used by user_info? */
 
 	if (temporary_user) {
 		g_free(user->client_info);
@@ -987,7 +988,7 @@
 		g_free(user->image_url);
 		g_free(user);
 	}
-
+	g_free(username);
 }
 
 /** Retrieve a user's profile. 
@@ -1166,7 +1167,7 @@
 	/* TODO: more elegant solution than below. attach whole message? */
 	/* Special elements name beginning with '_', we'll use internally within the
 	 * program (did not come directly from the wire). */
-	msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, username);
+	msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, username); /* This makes 'msg' the owner of 'username' */
   
 	/* TODO: attach more useful information, like ImageURL */
 
@@ -1802,8 +1803,7 @@
 		}
 		purple_connection_error(session->gc, full_errmsg);
 	} else {
-		purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")), 
-				full_errmsg, NULL);
+		purple_notify_error(session->account, _("MySpaceIM Error"), full_errmsg, NULL);
 	}
 
 	g_free(full_errmsg);
@@ -2674,6 +2674,7 @@
 	/* TODO: other fields, store in 'user' */
 
 	msim_msg_free(contact_info);
+	g_free(username);
 }
 
 /** Add first ContactID in contact_info to buddy's list. Used to add
--- a/libpurple/protocols/myspace/user.c	Tue Oct 02 04:38:10 2007 +0000
+++ b/libpurple/protocols/myspace/user.c	Tue Oct 02 06:13:27 2007 +0000
@@ -30,10 +30,10 @@
 static gchar *
 msim_format_now_playing(gchar *band, gchar *song)
 {
-	if ((band && strlen(band)) || (song && strlen(song))) {
+	if ((band && *band) || (song && *song)) {
 		return g_strdup_printf("%s - %s",
-			(band && strlen(band)) ? band : "Unknown Artist",
-			(song && strlen(song)) ? song : "Unknown Song");
+			(band && *band) ? band : "Unknown Artist",
+			(song && *song) ? song : "Unknown Song");
 	} else {
 		return NULL;
 	}
@@ -99,58 +99,63 @@
 
 	if (full) {
 		/* TODO: link to username, if available */
-		purple_notify_user_info_add_pair(user_info, _("Profile"),
-				g_strdup_printf("<a href=\"http://myspace.com/%d\">http://myspace.com/%d</a>",
-					uid, uid));
+		char *profile = g_strdup_printf("<a href=\"http://myspace.com/%d\">http://myspace.com/%d</a>",
+				uid, uid);
+		purple_notify_user_info_add_pair(user_info, _("Profile"), profile);
+		g_free(profile);
 	}
 
 
 	/* a/s/l...the vitals */
 	if (user->age) {
-		purple_notify_user_info_add_pair(user_info, _("Age"),
-				g_strdup_printf("%d", user->age));
+		char age[16];
+		g_snprintf(age, sizeof(age), "%d", user->age);
+		purple_notify_user_info_add_pair(user_info, _("Age"), age);
 	}
 
-	if (user->gender && strlen(user->gender)) {
+	if (user->gender && *user->gender) {
 		purple_notify_user_info_add_pair(user_info, _("Gender"), user->gender);
 	}
 
-	if (user->location && strlen(user->location)) {
+	if (user->location && *user->location) {
 		purple_notify_user_info_add_pair(user_info, _("Location"), user->location);
 	}
 
 	/* Other information */
-	if (user->headline && strlen(user->headline)) {
+	if (user->headline && *user->headline) {
 		purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline);
 	}
 
 	str = msim_format_now_playing(user->band_name, user->song_name);
-	if (str && strlen(str)) {
+	if (str && *str) {
 		purple_notify_user_info_add_pair(user_info, _("Song"), str);
 	}
+	g_free(str);
 
 	/* Note: total friends only available if looked up by uid, not username. */
 	if (user->total_friends) {
-		purple_notify_user_info_add_pair(user_info, _("Total Friends"),
-			g_strdup_printf("%d", user->total_friends));
+		char friends[16];
+		g_snprintf(friends, sizeof(friends), "%d", user->total_friends);
+		purple_notify_user_info_add_pair(user_info, _("Total Friends"), friends);
 	}
 
 	if (full) {
 		/* Client information */
+		char *client = NULL;
 
 		str = user->client_info;
 		cv = user->client_cv;
 
 		if (str && cv != 0) {
-			purple_notify_user_info_add_pair(user_info, _("Client Version"),
-					g_strdup_printf("%s (build %d)", str, cv));
+			client = g_strdup_printf("%s (build %d)", str, cv);
 		} else if (str) {
-			purple_notify_user_info_add_pair(user_info, _("Client Version"),
-					g_strdup(str));
+			client = g_strdup(str);
 		} else if (cv) {
-			purple_notify_user_info_add_pair(user_info, _("Client Version"),
-					g_strdup_printf("Build %d", cv));
+			client = g_strdup_printf("Build %d", cv);
 		}
+		if (client && *client)
+			purple_notify_user_info_add_pair(user_info, _("Client Version"), client);
+		g_free(client);
 	}
 }