Attached is a patch to fix a memory leak for a single result in mutt_query_complete.
-Kevin
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1412921829 -28800 # Fri Oct 10 14:17:09 2014 +0800 # Node ID 48227dabf9f85ea9febf757398f8005a904acff5 # Parent 4a814b05874f6863e8a70aa7d21fd0182646b7c0 Fix a memory leak in mutt_query_complete. When a single result was returned, it was written to the buffer and returned, but the query result was never freed. This patch creates a free_query function and changes the code to use that everywhere. diff --git a/query.c b/query.c --- a/query.c +++ b/query.c @@ -65,16 +65,35 @@ if(!tmp->next && !tmp->personal) tmp->personal = safe_strdup (r->name); mutt_addrlist_to_idna (tmp, NULL); return tmp; } +static void free_query (QUERY **query) +{ + QUERY *p; + + if (!query) + return; + + while (*query) + { + p = *query; + *query = (*query)->next; + + rfc822_free_address (&p->addr); + FREE (&p->name); + FREE (&p->other); + FREE (&p); + } +} + static QUERY *run_query (char *s, int quiet) { FILE *fp; QUERY *first = NULL; QUERY *cur = NULL; char cmd[_POSIX_PATH_MAX]; char *buf = NULL; size_t buflen; @@ -253,16 +272,17 @@ /* only one response? */ if (results->next == NULL) { tmpa = result_to_addr (results); mutt_addrlist_to_local (tmpa); buf[0] = '\0'; rfc822_write_address (buf, buflen, tmpa, 0); rfc822_free_address (&tmpa); + free_query (&results); mutt_clear_error (); return (0); } /* multiple results, choose from query menu */ query_menu (buf, buflen, results, 1); } return (0); } @@ -343,26 +363,17 @@ menu->redraw = REDRAW_FULL; if (newresults) { snprintf (title, sizeof (title), _("Query '%s'"), buf); if (op == OP_QUERY) { - queryp = results; - while (queryp) - { - rfc822_free_address (&queryp->addr); - FREE (&queryp->name); - FREE (&queryp->other); - results = queryp->next; - FREE (&queryp); - queryp = results; - } + free_query (&results); results = newresults; FREE (&QueryTable); } else { /* append */ for (queryp = results; queryp->next; queryp = queryp->next); @@ -515,26 +526,17 @@ ADDRESS *tmpa = result_to_addr (QueryTable[menu->current].data); mutt_addrlist_to_local (tmpa); rfc822_write_address (buf, buflen, tmpa, 0); rfc822_free_address (&tmpa); } } - queryp = results; - while (queryp) - { - rfc822_free_address (&queryp->addr); - FREE (&queryp->name); - FREE (&queryp->other); - results = queryp->next; - FREE (&queryp); - queryp = results; - } + free_query (&results); FREE (&QueryTable); /* tell whoever called me to redraw the screen when I return */ set_option (OPTNEEDREDRAW); } mutt_menuDestroy (&menu); }
signature.asc
Description: PGP signature
