From: David Levine Date: Sat, 8 Nov 2014 05:08:13 +0000 (-0600) Subject: Changed content_charset() to not cache, so the user can always, and X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/fdeb1f8d93ee914a3493c5331a24353c1febb87d?ds=sidebyside;hp=--cc Changed content_charset() to not cache, so the user can always, and should, free the return value. --- fdeb1f8d93ee914a3493c5331a24353c1febb87d diff --git a/uip/mhparse.c b/uip/mhparse.c index 69bb542e..56374b23 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -3640,21 +3640,16 @@ bad_quote: } /* - * Return the charset for a particular content type. Return pointer is - * only valid until the next call to content_charset(). + * Return the charset for a particular content type. */ char * content_charset (CT ct) { - static char *ret_charset = NULL; - - if (ret_charset != NULL) { - free(ret_charset); - } + char *ret_charset = NULL; ret_charset = get_param(ct->c_ctinfo.ci_first_pm, "charset", '?', 0); - return ret_charset ? ret_charset : "US-ASCII"; + return getcpy (ret_charset ? ret_charset : "US-ASCII"); } diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 6236352c..b76a588b 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -354,10 +354,12 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked, struct format * if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) return NOTOK; } else { + char *charset = content_charset (ct); admonish (NULL, "unable to convert character set%s%s to %s", ct->c_partno ? " of part " : "", ct->c_partno ? ct->c_partno : "", - content_charset (ct)); + charset); + free (charset); } } @@ -1037,6 +1039,7 @@ convert_charset (CT ct, char *dest_charset, int *message_mods) { if ((conv_desc = iconv_open (dest_charset, src_charset)) == (iconv_t) -1) { advise (NULL, "Can't convert %s to %s", src_charset, dest_charset); + free (src_charset); return NOTOK; } @@ -1177,6 +1180,7 @@ iconv_start: #endif /* ! HAVE_ICONV */ } + free (src_charset); return status; } @@ -1201,9 +1205,8 @@ convert_content_charset (CT ct, char **file) { } else { status = NOTOK; } - - free (charset); } + free (charset); #else /* ! HAVE_ICONV */ NMH_UNUSED (ct); NMH_UNUSED (file);