changeset 20058:5103485b4b26

Plug some memory leaks.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 15 Sep 2007 18:27:01 +0000
parents 27754fc4d72e
children dae7c3c091e0 fee0eea83e58
files libpurple/protocols/jabber/adhoccommands.c libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/message.c libpurple/protocols/jabber/presence.c libpurple/protocols/jabber/usernick.c libpurple/protocols/jabber/usertune.c
diffstat 7 files changed, 61 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/adhoccommands.c	Sat Sep 15 16:48:23 2007 +0000
+++ b/libpurple/protocols/jabber/adhoccommands.c	Sat Sep 15 18:27:01 2007 +0000
@@ -151,8 +151,11 @@
 		/* display result */
 		xmlnode *note = xmlnode_get_child(command,"note");
 		
-		if(note)
-			purple_notify_info(NULL, xmlnode_get_attrib(packet, "from"), xmlnode_get_data(note), NULL);
+		if(note) {
+			char *data = xmlnode_get_data(note);
+			purple_notify_info(NULL, xmlnode_get_attrib(packet, "from"), data, NULL);
+			g_free(data);
+		}
 		
 		if(xdata)
 			jabber_x_data_request(js, xdata, (jabber_x_data_cb)do_adhoc_ignoreme, NULL);
--- a/libpurple/protocols/jabber/buddy.c	Sat Sep 15 16:48:23 2007 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Sat Sep 15 18:27:01 2007 +0000
@@ -1455,10 +1455,13 @@
 		return;
 	
 	img = purple_base64_decode(b64data, &size);
-	if(!img)
+	if(!img) {
+		g_free(b64data);
 		return;
+	}
 	
 	purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, img, size, checksum);
+	g_free(b64data);
 }
 
 void jabber_buddy_avatar_update_metadata(JabberStream *js, const char *from, xmlnode *items) {
--- a/libpurple/protocols/jabber/jabber.c	Sat Sep 15 16:48:23 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Sep 15 18:27:01 2007 +0000
@@ -813,7 +813,7 @@
 		if(account->registration_cb)
 			(account->registration_cb)(account, FALSE, account->registration_cb_user_data);
 		jabber_connection_schedule_close(cbdata->js);
-}
+	}
 	g_free(cbdata->who);
 	g_free(cbdata);
 }
@@ -882,12 +882,12 @@
 				if((href = xmlnode_get_data(url))) {
 					purple_notify_uri(NULL, href);
 					g_free(href);
-				if(js->registration) {
-					js->gc->wants_to_die = TRUE;
-					if(account->registration_cb) /* succeeded, but we have no login info */
-						(account->registration_cb)(account, TRUE, account->registration_cb_user_data);
-					jabber_connection_schedule_close(js);
-				}
+					if(js->registration) {
+						js->gc->wants_to_die = TRUE;
+						if(account->registration_cb) /* succeeded, but we have no login info */
+							(account->registration_cb)(account, TRUE, account->registration_cb_user_data);
+						jabber_connection_schedule_close(js);
+					}
 					return;
 				}
 			}
@@ -987,14 +987,14 @@
 		purple_request_field_group_add_field(group, field);
 	}
 
-		if((y = xmlnode_get_child(query, "instructions")))
-			instructions = xmlnode_get_data(y);
+	if((y = xmlnode_get_child(query, "instructions")))
+		instructions = xmlnode_get_data(y);
 	else if(registered)
 		instructions = g_strdup(_("Please fill out the information below "
 					"to change your account registration."));
-		else
-			instructions = g_strdup(_("Please fill out the information below "
-						"to register your new account."));
+	else
+		instructions = g_strdup(_("Please fill out the information below "
+					"to register your new account."));
 
 	cbdata = g_new0(JabberRegisterCBData, 1);
 	cbdata->js = js;
@@ -1019,8 +1019,8 @@
 		g_free(title);
 	}
 
-		g_free(instructions);
-	}
+	g_free(instructions);
+}
 
 void jabber_register_start(JabberStream *js)
 {
--- a/libpurple/protocols/jabber/message.c	Sat Sep 15 16:48:23 2007 +0000
+++ b/libpurple/protocols/jabber/message.c	Sat Sep 15 18:27:01 2007 +0000
@@ -324,7 +324,7 @@
 	if(type) {
 		if(!strcmp(type, "normal"))
 			jm->type = JABBER_MESSAGE_NORMAL;
-	else if(!strcmp(type, "chat"))
+		else if(!strcmp(type, "chat"))
 			jm->type = JABBER_MESSAGE_CHAT;
 		else if(!strcmp(type, "groupchat"))
 			jm->type = JABBER_MESSAGE_GROUPCHAT;
--- a/libpurple/protocols/jabber/presence.c	Sat Sep 15 16:48:23 2007 +0000
+++ b/libpurple/protocols/jabber/presence.c	Sat Sep 15 18:27:01 2007 +0000
@@ -192,16 +192,11 @@
 		jabber_tune_set(js->gc, &tuneinfo);
 		
 		/* update old values */
-		if(js->old_artist)
-			g_free(js->old_artist);
-		if(js->old_title)
-			g_free(js->old_title);
-		if(js->old_source)
-			g_free(js->old_source);
-		if(js->old_uri)
-			g_free(js->old_uri);
-		if(js->old_track)
-			g_free(js->old_track);
+		g_free(js->old_artist);
+		g_free(js->old_title);
+		g_free(js->old_source);
+		g_free(js->old_uri);
+		g_free(js->old_track);
 		js->old_artist = g_strdup(artist);
 		js->old_title = g_strdup(title);
 		js->old_source = g_strdup(source);
--- a/libpurple/protocols/jabber/usernick.c	Sat Sep 15 16:48:23 2007 +0000
+++ b/libpurple/protocols/jabber/usernick.c	Sat Sep 15 18:27:01 2007 +0000
@@ -33,7 +33,7 @@
 	xmlnode *item = xmlnode_get_child(items, "item");
 	JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE);
 	xmlnode *nick;
-	const char *nickname = NULL;
+	char *nickname = NULL;
 	
 	/* ignore the tune of people not on our buddy list */
 	if (!buddy || !item)
@@ -43,8 +43,8 @@
 	if (!nick)
 		return;
 	nickname = xmlnode_get_data(nick);
-
 	serv_got_alias(js->gc, from, nickname);
+	g_free(nickname);
 }
 
 static void do_nick_set(JabberStream *js, const char *nick) {
@@ -64,7 +64,7 @@
 }
 
 static void do_nick_got_own_nick_cb(JabberStream *js, const char *from, xmlnode *items) {
-	const char *oldnickname = NULL;
+	char *oldnickname = NULL;
 	xmlnode *item = xmlnode_get_child(items,"item");
 	
 	if(item) {
@@ -77,6 +77,7 @@
 		_("This information is visible to all contacts on your contact list, so choose something appropriate."),
 		oldnickname, FALSE, FALSE, NULL, _("Set"), PURPLE_CALLBACK(do_nick_set), _("Cancel"), NULL,
 		purple_connection_get_account(js->gc), NULL, NULL, js);
+	g_free(oldnickname);
 }
 
 static void do_nick_set_nick(PurplePluginAction *action) {
--- a/libpurple/protocols/jabber/usertune.c	Sat Sep 15 16:48:23 2007 +0000
+++ b/libpurple/protocols/jabber/usertune.c	Sat Sep 15 18:27:01 2007 +0000
@@ -41,48 +41,61 @@
 	if (!buddy || !item)
 		return;
 	
-	tuneinfodata.artist = "";
-	tuneinfodata.title = "";
-	tuneinfodata.album = "";
-	tuneinfodata.track = "";
+	tuneinfodata.artist = NULL;
+	tuneinfodata.title = NULL;
+	tuneinfodata.album = NULL;
+	tuneinfodata.track = NULL;
 	tuneinfodata.time = -1;
-	tuneinfodata.url = "";
-	
+	tuneinfodata.url = NULL;
+
 	tune = xmlnode_get_child_with_namespace(item, "tune", "http://jabber.org/protocol/tune");
 	if (!tune)
 		return;
+	resource = jabber_buddy_find_resource(buddy, NULL);
+	if(!resource)
+		return; /* huh? */
 	for (tuneinfo = tune->child; tuneinfo; tuneinfo = tuneinfo->next) {
 		if (tuneinfo->type == XMLNODE_TYPE_TAG) {
 			if (!strcmp(tuneinfo->name, "artist")) {
-				if (tuneinfodata.artist[0] == '\0') /* only pick the first one */
+				if (tuneinfodata.artist == NULL) /* only pick the first one */
 					tuneinfodata.artist = xmlnode_get_data(tuneinfo);
 			} else if (!strcmp(tuneinfo->name, "length")) {
 				if (tuneinfodata.time == -1) {
 					char *length = xmlnode_get_data(tuneinfo);
 					if (length)
 						tuneinfodata.time = strtol(length, NULL, 10);
+					g_free(length);
 				}
 			} else if (!strcmp(tuneinfo->name, "source")) {
-				if (tuneinfodata.album[0] == '\0') /* only pick the first one */
+				if (tuneinfodata.album == NULL) /* only pick the first one */
 					tuneinfodata.album = xmlnode_get_data(tuneinfo);
 			} else if (!strcmp(tuneinfo->name, "title")) {
-				if (tuneinfodata.title[0] == '\0') /* only pick the first one */
+				if (tuneinfodata.title == NULL) /* only pick the first one */
 					tuneinfodata.title = xmlnode_get_data(tuneinfo);
 			} else if (!strcmp(tuneinfo->name, "track")) {
-				if (tuneinfodata.track[0] == '\0') /* only pick the first one */
+				if (tuneinfodata.track == NULL) /* only pick the first one */
 					tuneinfodata.track = xmlnode_get_data(tuneinfo);
 			} else if (!strcmp(tuneinfo->name, "uri")) {
-				if (tuneinfodata.url[0] == '\0') /* only pick the first one */
+				if (tuneinfodata.url == NULL) /* only pick the first one */
 					tuneinfodata.url = xmlnode_get_data(tuneinfo);
 			}
 		}
 	}
-	resource = jabber_buddy_find_resource(buddy, NULL);
-	if(!resource)
-		return; /* huh? */
 	status_id = jabber_buddy_state_get_status_id(resource->state);
 
-	purple_prpl_got_user_status(js->gc->account, from, status_id, PURPLE_TUNE_ARTIST, tuneinfodata.artist, PURPLE_TUNE_TITLE, tuneinfodata.title, PURPLE_TUNE_ALBUM, tuneinfodata.album, PURPLE_TUNE_TRACK, tuneinfodata.track, PURPLE_TUNE_TIME, tuneinfodata.time, PURPLE_TUNE_URL, tuneinfodata.url, NULL);
+	purple_prpl_got_user_status(js->gc->account, from, status_id,
+			PURPLE_TUNE_ARTIST, tuneinfodata.artist,
+			PURPLE_TUNE_TITLE, tuneinfodata.title,
+			PURPLE_TUNE_ALBUM, tuneinfodata.album,
+			PURPLE_TUNE_TRACK, tuneinfodata.track,
+			PURPLE_TUNE_TIME, tuneinfodata.time,
+			PURPLE_TUNE_URL, tuneinfodata.url, NULL);
+
+	g_free(tuneinfodata.artist);
+	g_free(tuneinfodata.title);
+	g_free(tuneinfodata.album);
+	g_free(tuneinfodata.track);
+	g_free(tuneinfodata.url);
 }
 
 void jabber_tune_init(void) {