# HG changeset patch # User Sadrul Habib Chowdhury # Date 1222158814 0 # Node ID 14915e96311e86f94f5beca9ba93aa7cbc9192af # Parent 2c6c9d72f54f1331a6b0fa7dabdfa28166d4210c 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. diff -r 2c6c9d72f54f -r 14915e96311e libpurple/protocols/jabber/message.c --- a/libpurple/protocols/jabber/message.c Tue Sep 23 07:51:55 2008 +0000 +++ b/libpurple/protocols/jabber/message.c Tue Sep 23 08:33:34 2008 +0000 @@ -394,7 +394,7 @@ 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 @@ } } + g_free(markup); return g_string_free(out, FALSE); } @@ -481,7 +482,7 @@ smiley */ typedef struct { PurpleConversation *conv; - const gchar *alt; + gchar *alt; } JabberDataRef; static void @@ -511,7 +512,7 @@ } else { purple_debug_error("jabber", "Unknown response to data request\n"); } - + g_free(ref->alt); g_free(ref); } @@ -526,7 +527,7 @@ 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 @@ /* 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 @@ 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 @@ 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;