Mercurial > pidgin.yaz
changeset 19728:d397000d32fc
Various leakfixes and preventing unnecessary allocations.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 11 Sep 2007 04:06:56 +0000 |
parents | bc0157120924 |
children | 1b8af105614d |
files | libpurple/protocols/jabber/caps.c |
diffstat | 1 files changed, 39 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/caps.c Tue Sep 11 03:43:19 2007 +0000 +++ b/libpurple/protocols/jabber/caps.c Tue Sep 11 04:06:56 2007 +0000 @@ -116,8 +116,14 @@ static void jabber_caps_load(void) { xmlnode *capsdata = purple_util_read_xml_from_file(JABBER_CAPS_FILENAME, "XMPP capabilities cache"); xmlnode *client; - if(!capsdata || strcmp(capsdata->name, "capabilities")) + + if(!capsdata) return; + + if (strcmp(capsdata->name, "capabilities") != 0) { + xmlnode_free(capsdata); + return; + } for(client = capsdata->child; client; client = client->next) { if(client->type != XMLNODE_TYPE_TAG) @@ -183,6 +189,7 @@ g_hash_table_replace(capstable, key, value); } } + xmlnode_free(capsdata); } static void jabber_caps_store_ext(gpointer key, gpointer value, gpointer user_data) { @@ -238,9 +245,13 @@ } static void jabber_caps_store(void) { + char *str; xmlnode *root = xmlnode_new("capabilities"); g_hash_table_foreach(capstable, jabber_caps_store_client, root); - purple_util_write_data_to_file(JABBER_CAPS_FILENAME, xmlnode_to_formatted_str(root, NULL), -1); + str = xmlnode_to_formatted_str(root, NULL); + xmlnode_free(root); + purple_util_write_data_to_file(JABBER_CAPS_FILENAME, str, -1); + g_free(str); } /* this function assumes that all information is available locally */ @@ -250,13 +261,11 @@ JabberCapsValue *caps; GList *iter; - key->node = g_strdup(node); - key->ver = g_strdup(ver); + key->node = (char *)node; + key->ver = (char *)ver; caps = g_hash_table_lookup(capstable,key); - g_free(key->node); - g_free(key->ver); g_free(key); /* join all information */ @@ -360,24 +369,23 @@ xmlnode *child; jabber_ext_userdata *extuserdata = data; jabber_caps_cbplususerdata *userdata = extuserdata->userdata; - JabberCapsKey *clientkey = g_new0(JabberCapsKey, 1); JabberCapsValue *client; - JabberCapsValueExt *value = g_new0(JabberCapsValueExt, 1); const char *node = extuserdata->node; const char *key; --userdata->extOutstanding; if(node) { - clientkey->node = g_strdup(userdata->node); - clientkey->ver = g_strdup(userdata->ver); - + JabberCapsValueExt *value = g_new0(JabberCapsValueExt, 1); + + JabberCapsKey *clientkey = g_new0(JabberCapsKey, 1); + clientkey->node = userdata->node; + clientkey->ver = userdata->ver; + client = g_hash_table_lookup(capstable,clientkey); - - g_free(clientkey->node); - g_free(clientkey->ver); + g_free(clientkey); - + /* split node by #, key either points to \0 or the correct ext afterwards */ for(key = node; key[0] != '\0'; ++key) { if(key[0] == '#') { @@ -488,22 +496,20 @@ int i; gchar **splat = g_strsplit(originalext, " ", 0); for(i =0; splat[i]; i++) { - userdata->ext = g_list_append(userdata->ext, g_strdup(splat[i])); + userdata->ext = g_list_append(userdata->ext, splat[i]); ++userdata->extOutstanding; } - g_strfreev(splat); + g_free(splat); } g_free(originalext); - - key->node = g_strdup(node); - key->ver = g_strdup(ver); - + + key->node = (char *)node; + key->ver = (char *)ver; + client = g_hash_table_lookup(capstable, key); - - g_free(key->node); - g_free(key->ver); + g_free(key); - + if(!client) { JabberIq *iq = jabber_iq_new_query(js,JABBER_IQ_GET,"http://jabber.org/protocol/disco#info"); xmlnode *query = xmlnode_get_child_with_namespace(iq->node,"query","http://jabber.org/protocol/disco#info"); @@ -511,31 +517,33 @@ xmlnode_set_attrib(query, "node", nodever); g_free(nodever); xmlnode_set_attrib(iq->node, "to", who); - + jabber_iq_set_callback(iq,jabber_caps_client_iqcb,userdata); jabber_iq_send(iq); } else { - GList *iter; + GList *iter; /* fetch unknown exts only */ for(iter = userdata->ext; iter; iter = g_list_next(iter)) { JabberCapsValueExt *extvalue = g_hash_table_lookup(client->ext, (const char*)iter->data); JabberIq *iq; xmlnode *query; char *nodever; - jabber_ext_userdata *ext_data = g_new0(jabber_ext_userdata, 1); - + jabber_ext_userdata *ext_data; + if(extvalue) { /* we already have this ext, don't bother with it */ --userdata->extOutstanding; continue; } - + + ext_data = g_new0(jabber_ext_userdata, 1); + iq = jabber_iq_new_query(js,JABBER_IQ_GET,"http://jabber.org/protocol/disco#info"); query = xmlnode_get_child_with_namespace(iq->node,"query","http://jabber.org/protocol/disco#info"); nodever = g_strdup_printf("%s#%s", node, (const char*)iter->data); xmlnode_set_attrib(query, "node", nodever); xmlnode_set_attrib(iq->node, "to", who); - + ext_data->node = nodever; ext_data->userdata = userdata;