]> diplodocus.org Git - nmh/blobdiff - uip/inc.c
Garbage collect closefds()
[nmh] / uip / inc.c
index d65c46fbad8eb54f56428614005d8cea2750d061..fecef370c96cafb80eb791e29fe3e5a46c5dd3a3 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
  */
 #endif
 
-#include <h/mh.h>
-#include <h/utils.h>
+#include "h/mh.h"
+#include "sbr/fmt_new.h"
+#include "sbr/dtime.h"
+#include "scansbr.h"
+#include "sbr/m_name.h"
+#include "sbr/m_gmprot.h"
+#include "sbr/getarguments.h"
+#include "sbr/concat.h"
+#include "sbr/seq_setunseen.h"
+#include "sbr/seq_setcur.h"
+#include "sbr/seq_save.h"
+#include "sbr/smatch.h"
+#include "sbr/getfolder.h"
+#include "sbr/ext_hook.h"
+#include "sbr/folder_read.h"
+#include "sbr/folder_realloc.h"
+#include "sbr/folder_free.h"
+#include "sbr/context_save.h"
+#include "sbr/context_replace.h"
+#include "sbr/context_find.h"
+#include "sbr/ambigsw.h"
+#include "sbr/path.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/error.h"
+#include "h/utils.h"
 #include <fcntl.h>
-#include <h/dropsbr.h>
-#include <h/popsbr.h>
-#include <h/fmt_scan.h>
-#include <h/scansbr.h>
-#include <h/signals.h>
-#include <h/tws.h>
-#include <h/mts.h>
+#include "h/dropsbr.h"
+#include "popsbr.h"
+#include "h/fmt_scan.h"
+#include "h/signals.h"
+#include "h/tws.h"
+#include "h/mts.h"
 #include "h/done.h"
 #include "sbr/lock_file.h"
 #include "sbr/m_maildir.h"
@@ -99,7 +122,7 @@ static struct Maildir_entry {
        time_t mtime;
 } *Maildir = NULL;
 static int num_maildir_entries = 0;
-static int snoop = 0;
+static bool snoop;
 
 typedef struct {
     FILE *mailout;
@@ -194,6 +217,7 @@ main (int argc, char **argv)
     FILE *aud = NULL;
     char b[PATH_MAX + 1];
     char *maildir_copy = NULL; /* copy of mail directory because the static gets overwritten */
+    charstring_t scanl = NULL;
 
     int nmsgs, nbytes;
     char *MAILHOST_env_variable;
@@ -329,7 +353,7 @@ main (int argc, char **argv)
                continue;
 
            case SNOOPSW:
-               snoop++;
+               snoop = true;
                continue;
        
            case SASLSW:
@@ -590,7 +614,6 @@ main (int argc, char **argv)
 
         hghnum = msgnum = mp->hghmsg;
        for (i = 1; i <= nmsgs; i++) {
-           charstring_t scanl = NULL;
 
            msgnum++;
             cp = mh_xstrdup(m_name (msgnum));
@@ -632,7 +655,9 @@ main (int argc, char **argv)
                    fflush (stdout);
                break;
            }
-           charstring_free (scanl);
+
+           if (scanl)
+               charstring_clear (scanl);
 
             if (ferror(pf) || fclose (pf)) {
                 int e = errno;
@@ -649,6 +674,9 @@ main (int argc, char **argv)
            scan_finished();
        }
 
+       charstring_free (scanl);
+       scanl = NULL;
+
        if (pop_quit () == NOTOK)
            die("%s", response);
 
@@ -658,8 +686,6 @@ main (int argc, char **argv)
        scan_detect_mbox_style (in);            /* the MAGIC invocation... */
        hghnum = msgnum = mp->hghmsg;
        for (;;) {
-           charstring_t scanl = NULL;
-
            /* create scanline for new message */
            switch (incerr = scan (in, msgnum + 1, msgnum + 1, nfs, width,
                              msgnum == hghnum && chgflag, 1, NULL, 0L, noisy,
@@ -696,16 +722,18 @@ main (int argc, char **argv)
                if (noisy)
                    fflush (stdout);
 
+               charstring_clear (scanl);
                msgnum++;
                continue;
            }
-           charstring_free (scanl);
 
            /* If we get here there was some sort of error from scan(),
             * so stop processing anything more from the spool.
             */
            break;
        }
+       charstring_free (scanl);
+       scanl = NULL;
 
     } else {
         /* Mail from Maildir. */
@@ -715,8 +743,6 @@ main (int argc, char **argv)
 
        hghnum = msgnum = mp->hghmsg;
        for (i = 0; i < num_maildir_entries; i++) {
-           charstring_t scanl = NULL;
-
            msgnum++;
 
            sp = Maildir[i].filename;
@@ -780,7 +806,7 @@ main (int argc, char **argv)
                    fflush (stdout);
                break;
            }
-           charstring_free (scanl);
+           charstring_clear (scanl);
 
            if (ferror(pf) || fclose (pf)) {
                int e = errno;
@@ -798,6 +824,8 @@ main (int argc, char **argv)
            scan_finished();
        }
        free (Maildir); /* From now on Maildir is just a flag - don't dref! */
+       charstring_free (scanl);
+       scanl = NULL;
     }
 
     scan_finished ();