pidgin: d7476bfe: Another memory leak fix. Also, keep a co...

sadrul at pidgin.im sadrul at pidgin.im
Tue Sep 23 04:25:24 EDT 2008


-----------------------------------------------------------------
Revision: d7476bfe7f9003553f7b3ea48491f4cebd192098
Ancestor: e6fb210583e50d36bcfe1d27266b2725786dd05d
Author: sadrul at pidgin.im
Date: 2008-09-23T08:33:34
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d7476bfe7f9003553f7b3ea48491f4cebd192098

Modified files:
        libpurple/protocols/jabber/message.c

ChangeLog: 

Another memory leak fix. Also, keep a copy of the alt-text in
JabberDataRef:alt, since by the time it's used, the text would have been
freed.
Also, fix a previous leak fix, which wouldn't work because the list was
being set to NULL after iterating over to the end.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/message.c	d0342107f0b2e688a985910981abb6376530f283
+++ libpurple/protocols/jabber/message.c	ac733ca657c7cce25ae8c5fafc2d0bf9a1ee055a
@@ -394,7 +394,7 @@ jabber_message_xml_to_string_strip_img_s
 static gchar *
 jabber_message_xml_to_string_strip_img_smileys(xmlnode *xhtml)
 {
-	const gchar *markup = xmlnode_to_str(xhtml, NULL);
+	gchar *markup = xmlnode_to_str(xhtml, NULL);
 	int len = strlen(markup);
 	int pos = 0;
 	GString *out = g_string_new(NULL);
@@ -456,6 +456,7 @@ jabber_message_xml_to_string_strip_img_s
 		}
 	}
 
+	g_free(markup);
 	return g_string_free(out, FALSE);
 }
 
@@ -481,7 +482,7 @@ typedef struct {
  smiley */
 typedef struct {
 	PurpleConversation *conv;
-	const gchar *alt;
+	gchar *alt;
 } JabberDataRef;
 
 static void
@@ -511,7 +512,7 @@ jabber_message_get_data_cb(JabberStream 
 	} else {
 		purple_debug_error("jabber", "Unknown response to data request\n");
 	}
-	
+	g_free(ref->alt);
 	g_free(ref);
 }
 
@@ -526,7 +527,7 @@ jabber_message_send_data_request(JabberS
 
 	xmlnode_set_attrib(request->node, "to", who);
 	ref->conv = conv;
-	ref->alt = alt;
+	ref->alt = g_strdup(alt);
 	jabber_iq_set_callback(request, jabber_message_get_data_cb, ref);
 	xmlnode_insert_child(request->node, data_request);
 
@@ -643,9 +644,8 @@ void jabber_message_parse(JabberStream *
 				/* note: if there were no smileys in the incoming message, or
 				  	if receiving custom smileys is turned off, smiley_refs will
 					be NULL */
-				for (; smiley_refs ; smiley_refs = g_list_next(smiley_refs)) {
-					const JabberSmileyRef *ref =
-						(JabberSmileyRef *) smiley_refs->data;
+				for (; smiley_refs ; smiley_refs = g_list_delete_link(smiley_refs, smiley_refs)) {
+					JabberSmileyRef *ref = (JabberSmileyRef *) smiley_refs->data;
 					const gchar *cid = ref->cid;
 					const gchar *alt = ref->alt;
 
@@ -671,6 +671,9 @@ void jabber_message_parse(JabberStream *
 								alt);
 						}
 					}
+					g_free(ref->cid);
+					g_free(ref->alt);
+					g_free(ref);
 				}
 
 			    /* Convert all newlines to whitespace. Technically, even regular, non-XML HTML is supposed to ignore newlines, but Pidgin has, as convention
@@ -680,14 +683,6 @@ void jabber_message_parse(JabberStream *
 					if (*c == '\n')
 						*c = ' ';
 				}
-
-				/* we don't need the list of CIDs anymore */
-				for (; smiley_refs ; smiley_refs = g_list_delete_link(smiley_refs, smiley_refs)) {
-					JabberSmileyRef *ref = (JabberSmileyRef *) smiley_refs->data;
-					g_free(ref->cid);
-					g_free(ref->alt);
-					g_free(ref);
-				}
 			}
 		} else if(!strcmp(child->name, "active") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
 			jm->chat_state = JM_STATE_ACTIVE;


More information about the Commits mailing list