Factor trim format function out
[mmh] / sbr / encode_rfc2047.c
index 852c261..4e4cbef 100644 (file)
@@ -204,7 +204,7 @@ field_encode_quoted(const char *name, char **value, const char *charset,
                                ** least one) until we get to the actual
                                ** text. Copy until we get to a non-space.
                                */
-                               output = mh_xmalloc(outlen);
+                               output = mh_xcalloc(outlen, sizeof(char));
                                q = output;
                                while (is_fws(*p)) {
                                        *q++ = *p++;
@@ -299,7 +299,7 @@ field_encode_quoted(const char *name, char **value, const char *charset,
        }
        *q = '\0';
 
-       free(*value);
+       mh_free0(value);
        *value = output;
 
        return 0;
@@ -340,7 +340,7 @@ utf8len(const char *p)
 static void
 unfold_header(char **value, int len)
 {
-       char *str = mh_xmalloc(len + 1);
+       char *str = mh_xcalloc(len + 1, sizeof(char));
        char *p = str, *q = *value;
 
        while (*q != '\0') {
@@ -367,7 +367,7 @@ unfold_header(char **value, int len)
        }
        *p = '\0';
 
-       free(*value);
+       mh_free0(value);
        *value = str;
 }
 
@@ -574,8 +574,7 @@ do_reformat:
 
                output = add(cp, output);
                column += len;
-               free(cp);
-               cp = NULL;
+               mh_free0(&cp);
        }
 
        /*
@@ -588,17 +587,17 @@ do_reformat:
 
        output = add("\n", output);
 
-       free(*value);
+       mh_free0(value);
        *value = output;
        output = NULL;
 
 out:
 
        if (tmpbuf) {
-               free(tmpbuf);
+               mh_free0(&tmpbuf);
        }
        if (output) {
-               free(output);
+               mh_free0(&output);
        }
 
        return errflag > 0;