]> diplodocus.org Git - nmh/blobdiff - uip/mhfree.c
Alright, things compile now, but don't link yet; need to write the
[nmh] / uip / mhfree.c
index 5fa2a59cfa3bc1ff3059aede1c28d8748e21a0f1..4fb46da7403f9b8b6aa28ccd57f9d3468991adbc 100644 (file)
@@ -30,6 +30,7 @@ static void free_text (CT);
 static void free_multi (CT);
 static void free_partial (CT);
 static void free_external (CT);
+static void free_pmlist (PM *);
 
 
 /*
@@ -47,14 +48,20 @@ free_content (CT ct)
      */
     free_header (ct);
 
-    if (ct->c_partno)
+    if (ct->c_partno) {
        free (ct->c_partno);
+       ct->c_partno = NULL;
+    }
 
-    if (ct->c_vrsn)
+    if (ct->c_vrsn) {
        free (ct->c_vrsn);
+       ct->c_vrsn = NULL;
+    }
 
-    if (ct->c_ctline)
+    if (ct->c_ctline) {
        free (ct->c_ctline);
+       ct->c_ctline = NULL;
+    }
 
     free_ctinfo (ct);
 
@@ -84,38 +91,64 @@ free_content (CT ct)
            break;
     }
 
-    if (ct->c_showproc)
+    if (ct->c_showproc) {
        free (ct->c_showproc);
-    if (ct->c_termproc)
+       ct->c_showproc = NULL;
+    }
+    if (ct->c_termproc) {
        free (ct->c_termproc);
-    if (ct->c_storeproc)
+       ct->c_termproc = NULL;
+    }
+    if (ct->c_storeproc) {
        free (ct->c_storeproc);
+       ct->c_storeproc = NULL;
+    }
 
-    if (ct->c_celine)
+    if (ct->c_celine) {
        free (ct->c_celine);
+       ct->c_celine = NULL;
+    }
 
     /* free structures for content encodings */
     free_encoding (ct, 1);
 
-    if (ct->c_id)
+    if (ct->c_id) {
        free (ct->c_id);
-    if (ct->c_descr)
+       ct->c_id = NULL;
+    }
+    if (ct->c_descr) {
        free (ct->c_descr);
-    if (ct->c_dispo)
+       ct->c_descr = NULL;
+    }
+    if (ct->c_dispo) {
        free (ct->c_dispo);
+       ct->c_dispo = NULL;
+    }
+    if (ct->c_dispo_type) {
+       free (ct->c_dispo_type);
+       ct->c_dispo_type = NULL;
+    }
+    free_pmlist (&ct->c_dispo_first);
 
     if (ct->c_file) {
        if (ct->c_unlink)
-           unlink (ct->c_file);
+           (void) m_unlink (ct->c_file);
        free (ct->c_file);
+       ct->c_file = NULL;
     }
-    if (ct->c_fp)
+    if (ct->c_fp) {
        fclose (ct->c_fp);
+       ct->c_fp = NULL;
+    }
 
-    if (ct->c_storage)
+    if (ct->c_storage) {
        free (ct->c_storage);
-    if (ct->c_folder)
+       ct->c_storage = NULL;
+    }
+    if (ct->c_folder) {
        free (ct->c_folder);
+       ct->c_folder = NULL;
+    }
 
     free (ct);
 }
@@ -150,7 +183,6 @@ free_header (CT ct)
 void
 free_ctinfo (CT ct)
 {
-    char **ap;
     CI ci;
 
     ci = &ct->c_ctinfo;
@@ -162,10 +194,7 @@ free_ctinfo (CT ct)
        free (ci->ci_subtype);
        ci->ci_subtype = NULL;
     }
-    for (ap = ci->ci_attrs; *ap; ap++) {
-       free (*ap);
-       *ap = NULL;
-    }
+    free_pmlist(&ci->ci_first_pm);
     if (ci->ci_comment) {
        free (ci->ci_comment);
        ci->ci_comment = NULL;
@@ -253,6 +282,30 @@ free_external (CT ct)
 }
 
 
+static void
+free_pmlist (PM *p)
+{
+    PM pm = *p, pm2;
+
+    while (pm != NULL) {
+       if (pm->pm_name)
+           free (pm->pm_name);
+       if (pm->pm_value)
+           free (pm->pm_value);
+       if (pm->pm_charset)
+           free (pm->pm_charset);
+       if (pm->pm_lang)
+           free (pm->pm_lang);
+       pm2 = pm->pm_next;
+       free(pm);
+       pm = pm2;
+    }
+
+    if (*p)
+       *p = NULL;
+}
+
+
 /*
  * Free data structures related to encoding/decoding
  * Content-Transfer-Encodings.
@@ -270,7 +323,7 @@ free_encoding (CT ct, int toplevel)
 
     if (ce->ce_file) {
        if (ce->ce_unlink)
-           unlink (ce->ce_file);
+           (void) m_unlink (ce->ce_file);
        free (ce->ce_file);
        ce->ce_file = NULL;
     }
@@ -286,9 +339,10 @@ freects_done (int status)
 {
     CT *ctp;
 
-    if ((ctp = cts))
-       for (; *ctp; ctp++)
-           free_content (*ctp);
+    for (ctp = cts; ctp && *ctp; ctp++)
+       free_content (*ctp);
+
+    free (cts);
 
     exit (status);
 }