]> diplodocus.org Git - nmh/commitdiff
Changed content_charset() to not cache, so the user can always, and
authorDavid Levine <levinedl@acm.org>
Sat, 8 Nov 2014 05:08:13 +0000 (23:08 -0600)
committerDavid Levine <levinedl@acm.org>
Sat, 8 Nov 2014 05:08:13 +0000 (23:08 -0600)
should, free the return value.

uip/mhparse.c
uip/mhshowsbr.c

index 69bb542e7c56cca2088ef18bc3addf9eeb6db77a..56374b230731e9da9860eef2e0461bcfc739519b 100644 (file)
@@ -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");
 }
 
 
index 6236352ca21da6c98efa9b7775588cc761df7dc5..b76a588bfe55c5708b18c86e302f7729dbf983eb 100644 (file)
@@ -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);