From 685fcb4eb4449b1cf3347af40c153525443db8cc Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Tue, 6 Sep 2005 01:46:46 +0000 Subject: [PATCH] Fix a memory leak in imap_utf7_decode and do a little cleanup on shutdown. Get a high five from valgrind. --- imap/utf7.c | 6 +++++- init.c | 42 ++++++++++++++++++++++++++++++++++++++++++ main.c | 1 + protos.h | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/imap/utf7.c b/imap/utf7.c index b5b871c82..29564fb2a 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -258,7 +258,11 @@ void imap_utf7_encode (char **s) { char *t = safe_strdup (*s); if (!mutt_convert_string (&t, Charset, "UTF-8", 0)) - utf8_to_utf7 (t, strlen (t), s, 0); + { + char *u7 = utf8_to_utf7 (t, strlen (t), NULL, 0); + FREE (s); + *s = u7; + } FREE (&t); } } diff --git a/init.c b/init.c index 35ef161e7..3d48ddd96 100644 --- a/init.c +++ b/init.c @@ -289,6 +289,48 @@ int mutt_extract_token (BUFFER *dest, BUFFER *tok, int flags) return 0; } +static void mutt_free_opt (struct option_t* p) +{ + REGEXP* pp; + + switch (p->type & DT_MASK) + { + case DT_ADDR: + rfc822_free_address ((ADDRESS**)p->data); + break; + case DT_RX: + pp = (REGEXP*)p->data; + FREE (&pp->pattern); + if (pp->rx) + { + regfree (pp->rx); + FREE (&pp->rx); + } + break; + case DT_PATH: + case DT_STR: + FREE ((char**)p->data); + break; + } +} + +/* clean up before quitting */ +void mutt_free_opts (void) +{ + int i; + + for (i = 0; MuttVars[i].option; i++) + mutt_free_opt (MuttVars + i); + + mutt_free_rx_list (&Alternates); + mutt_free_rx_list (&UnAlternates); + mutt_free_rx_list (&MailLists); + mutt_free_rx_list (&UnMailLists); + mutt_free_rx_list (&SubscribedLists); + mutt_free_rx_list (&UnSubscribedLists); + mutt_free_rx_list (&NoSpamList); +} + static void add_to_list (LIST **list, const char *str) { LIST *t, *last = NULL; diff --git a/main.c b/main.c index b6d46f677..774f88b92 100644 --- a/main.c +++ b/main.c @@ -958,6 +958,7 @@ int main (int argc, char **argv) #ifdef USE_SASL mutt_sasl_done (); #endif + mutt_free_opts (); mutt_endwin (Errorbuf); } diff --git a/protos.h b/protos.h index 3f75fd6ee..2ce8253c1 100644 --- a/protos.h +++ b/protos.h @@ -42,6 +42,7 @@ void mutt_buffer_free(BUFFER **); void mutt_buffer_add (BUFFER*, const char*, size_t); void mutt_buffer_addstr (BUFFER*, const char*); void mutt_buffer_addch (BUFFER*, char); +void mutt_free_opts (void); #define mutt_system(x) _mutt_system(x,0) int _mutt_system (const char *, int); -- 2.40.0