# HG changeset patch # User Mikael Berthe # Date 1165170590 -3600 # Node ID 2a3cfb98bd5e8f19cae8423fc0f474a201ac1e63 # Parent 866be086cc9bcf14f2e2710bc9ac5b278e6bf303 Fix memory leaks after calls to buddy_getresources() diff -r 866be086cc9b -r 2a3cfb98bd5e mcabber/src/commands.c --- a/mcabber/src/commands.c Sun Dec 03 12:00:17 2006 +0100 +++ b/mcabber/src/commands.c Sun Dec 03 19:29:50 2006 +0100 @@ -1282,7 +1282,7 @@ buffer = g_new(char, 4096); if (bjid) { - GSList *resources; + GSList *resources, *p_res; char *bstr = "unknown"; // Enter chat mode @@ -1320,21 +1320,21 @@ scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO); } } - for ( ; resources ; resources = g_slist_next(resources) ) { + for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) { gchar rprio; enum imstatus rstatus; const char *rst_msg; time_t rst_time; struct pgp_data *rpgp; - rprio = buddy_getresourceprio(bud, resources->data); - rstatus = buddy_getstatus(bud, resources->data); - rst_msg = buddy_getstatusmsg(bud, resources->data); - rst_time = buddy_getstatustime(bud, resources->data); - rpgp = buddy_resource_pgp(bud, resources->data); + rprio = buddy_getresourceprio(bud, p_res->data); + rstatus = buddy_getstatus(bud, p_res->data); + rst_msg = buddy_getstatusmsg(bud, p_res->data); + rst_time = buddy_getstatustime(bud, p_res->data); + rpgp = buddy_resource_pgp(bud, p_res->data); snprintf(buffer, 4095, "Resource: [%c] (%d) %s", imstatus2char[rstatus], - rprio, (char*)resources->data); + rprio, (char*)p_res->data); scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO); if (rst_msg) { snprintf(buffer, 4095, "Status message: %s", rst_msg); @@ -1360,7 +1360,9 @@ } } #endif + g_free(p_res->data); } + g_slist_free(resources); } else { if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name); scr_LogPrint(LPRINT_NORMAL, "Type: %s", @@ -1390,7 +1392,7 @@ { const char *bjid; char *buffer; - GSList *resources; + GSList *resources, *p_res; if (*arg) { scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter."); @@ -1408,22 +1410,23 @@ scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO); resources = buddy_getresources(bud); - for ( ; resources ; resources = g_slist_next(resources) ) { + for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) { enum imstatus rstatus; const char *rst_msg; - rstatus = buddy_getstatus(bud, resources->data); - rst_msg = buddy_getstatusmsg(bud, resources->data); + rstatus = buddy_getstatus(bud, p_res->data); + rst_msg = buddy_getstatusmsg(bud, p_res->data); snprintf(buffer, 4095, "[%c] %s", imstatus2char[rstatus], - (char*)resources->data); + (char*)p_res->data); scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO); if (rst_msg) { snprintf(buffer, 4095, "Status message: %s", rst_msg); scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE); } + g_free(p_res->data); } - + g_slist_free(resources); g_free(buffer); } diff -r 866be086cc9b -r 2a3cfb98bd5e mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Sun Dec 03 12:00:17 2006 +0100 +++ b/mcabber/src/jabglue.c Sun Dec 03 19:29:50 2006 +0100 @@ -998,7 +998,7 @@ void jb_request(const char *fjid, enum iqreq_type reqtype) { - GSList *resources; + GSList *resources, *p_res; GSList *roster_elt; void (*request_fn)(const char *); const char *strreqtype; @@ -1049,13 +1049,15 @@ (*request_fn)(fjid); // Let's send a request anyway... scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fjid); } - for ( ; resources ; resources = g_slist_next(resources) ) { + for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) { gchar *fulljid; - fulljid = g_strdup_printf("%s/%s", fjid, (char*)resources->data); + fulljid = g_strdup_printf("%s/%s", fjid, (char*)p_res->data); (*request_fn)(fulljid); scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fulljid); g_free(fulljid); + g_free(p_res->data); } + g_slist_free(resources); } // Join a MUC room diff -r 866be086cc9b -r 2a3cfb98bd5e mcabber/src/screen.c --- a/mcabber/src/screen.c Sun Dec 03 12:00:17 2006 +0100 +++ b/mcabber/src/screen.c Sun Dec 03 19:29:50 2006 +0100 @@ -1075,9 +1075,14 @@ // No status message for groups & MUC rooms if (!isgrp && !ismuc) { - GSList *resources = buddy_getresources(BUDDATA(current_buddy)); + GSList *resources, *p_res; + resources = buddy_getresources(BUDDATA(current_buddy)); msg = buddy_getstatusmsg(BUDDATA(current_buddy), resources ? resources->data : ""); + // Free the resources list data + for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) + g_free(p_res->data); + g_slist_free(resources); } else if (ismuc) { msg = buddy_gettopic(BUDDATA(current_buddy)); } @@ -1200,7 +1205,7 @@ for (i=0; idata : ""); - if (events & ROSTER_EVENT_PAUSED) + p_res ? p_res->data : ""); + if ((events & ROSTER_EVENT_PAUSED) && pending != '+') pending = '.'; - if (events & ROSTER_EVENT_COMPOSING) { + if (events & ROSTER_EVENT_COMPOSING) pending = '+'; - break; - } + g_free(p_res->data); } + g_slist_free(resources); // Display message notice if there is a message flag, but not // for unfolded groups.