]> Pileus Git - ~andy/fetchmail/commitdiff
Use alloca where possible.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 8 Oct 1998 05:31:22 +0000 (05:31 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 8 Oct 1998 05:31:22 +0000 (05:31 -0000)
svn path=/trunk/; revision=2076

NEWS
checkalias.c
driver.c
fetchmail.c
options.c
pop3.c
unmime.c

diff --git a/NEWS b/NEWS
index 5f48fe6612221576dfbcd24337876769dd1b4a78..2c8fd653516a8fac8bd07575720c8d32df87615a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,10 @@
                                Release Notes:
 
+fetchmail-4.6.1 ():
+* Fixed a minor memory leak in the IP-address-comparison code.
+* Mark Staveley's patch to suppress progress dots from non-detached daemon
+  fetchmails.
+
 fetchmail-4.6.0 (Fri Sep 18 13:17:17 EDT 1998):
 * Added Bill Adams's mailqueue.pl to the contrib directory.
 * Try to enable KPOP initialization to work even if `no dns' is on.
index eb045e3772b9092eb86e02b71d0250ad8f3db730..275e94102d2c5ab356b22780f2de6d8b0123c1ef 100644 (file)
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#if defined(HAVE_ALLOCA_H)
+#include <alloca.h>
+#else
+#ifdef _AIX
+ #pragma alloca
+#endif
+#endif
 #include "mx.h"
 #include "fetchmail.h"
 
@@ -48,7 +55,7 @@ static int is_ip_alias(const char *name1,const char *name2)
     {
        struct in_addr in;
        (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
-       host_a_addr = (address_e *)xmalloc(sizeof( address_e));
+       host_a_addr = (address_e *)alloca(sizeof( address_e));
        memset (host_a_addr,0, sizeof (address_e));
        host_a_addr->next = dummy_addr;
        (void) memcpy(&host_a_addr->address, *p, sizeof (in.s_addr));
@@ -62,7 +69,7 @@ static int is_ip_alias(const char *name1,const char *name2)
     {
        struct in_addr in;
        (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
-       host_b_addr = (address_e *)xmalloc(sizeof( address_e));
+       host_b_addr = (address_e *)alloca(sizeof( address_e));
        memset (host_b_addr,0, sizeof (address_e));
        host_b_addr->next = dummy_addr;
        (void) memcpy(&host_b_addr->address, *p, sizeof (in.s_addr));
@@ -121,7 +128,7 @@ int is_host_alias(const char *name, struct query *ctl)
 #else
     /*
      * The only code that calls the BIND library is here and in the
-     * start-of-run probe with gethostbyname(3).
+     * start-of-run probe with gethostbyname(3) under ETRN/Kerberos.
      *
      * We know DNS service was up at the beginning of the run.
      * If it's down, our nameserver has crashed.  We don't want to try
index 92108768f989f318f21bb800199105000bfb5e22..732855dcd3df7cb226f94ead4ab8e56172df4fbb 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -1633,7 +1633,7 @@ const char *canonical;    /* server name */
     Key_schedule schedule;
     int rem;
   
-    ticket = ((KTEXT) (malloc (sizeof (KTEXT_ST))));
+    ticket = ((KTEXT) (alloca (sizeof (KTEXT_ST))));
     rem = (krb_sendauth (0L, socket, ticket, "pop",
                         canonical,
                         ((char *) (krb_realmofhost (canonical))),
@@ -1644,7 +1644,6 @@ const char *canonical;    /* server name */
                         ((struct sockaddr_in *) 0),
                         ((struct sockaddr_in *) 0),
                         "KPOPV0.1"));
-    free (ticket);
     if (rem != KSUCCESS)
     {
        error(0, -1, "kerberos error %s", (krb_get_err_text (rem)));
index 41cff12102e449ba3691915843fedbaa15166424..32fe76596a137bfd135eb732741df0086a63ca93 100644 (file)
@@ -210,7 +210,7 @@ int main (int argc, char **argv)
 
     /* set up to do lock protocol */
 #define        FETCHMAIL_PIDFILE       "fetchmail.pid"
-    tmpbuf = xmalloc(strlen(home) + strlen(FETCHMAIL_PIDFILE) + 3);
+    tmpbuf = alloca(strlen(home) + strlen(FETCHMAIL_PIDFILE) + 3);
     if (!getuid())
        sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
     else {
@@ -352,7 +352,7 @@ int main (int argc, char **argv)
     }
 
     /* parse the ~/.netrc file (if present) for future password lookups. */
-    netrc_file = (char *) xmalloc (strlen (home) + 8);
+    netrc_file = (char *) alloca (strlen (home) + 8);
     strcpy (netrc_file, home);
     strcat (netrc_file, "/.netrc");
     netrc_list = parse_netrc(netrc_file);
@@ -403,9 +403,8 @@ int main (int argc, char **argv)
 #endif /* GSSAPI */
                 && !ctl->password)
            {
-               free(tmpbuf);
 #define        PASSWORD_PROMPT "Enter password for %s@%s: "
-               tmpbuf = xmalloc(strlen(PASSWORD_PROMPT) +
+               tmpbuf = alloca(strlen(PASSWORD_PROMPT) +
                                        strlen(ctl->remotename) +
                                        strlen(ctl->server.pollname) + 1);
                (void) sprintf(tmpbuf, PASSWORD_PROMPT,
@@ -415,10 +414,6 @@ int main (int argc, char **argv)
            }
        }
 
-    /* we don't need tmpbuf anymore */
-    free(tmpbuf);
-    tmpbuf = NULL;     /* firewall code */
-
     /*
      * Maybe time to go to demon mode...
      */
@@ -430,7 +425,7 @@ int main (int argc, char **argv)
     }
     else
 #endif
-       error_init(run.poll_interval == 0 && !run.logfile);
+       error_init((run.poll_interval == 0 || nodetach) && !run.logfile);
 
     if (run.poll_interval)
     {
index 6ae2f61eccaaeca6ddc9567c97d15b9a2167bdcf..aa63002b6cfad608084c5b63378f6023304c3cb1 100644 (file)
--- a/options.c
+++ b/options.c
@@ -7,6 +7,13 @@
 #include "config.h"
 
 #include <stdio.h>
+#if defined(HAVE_ALLOCA_H)
+#include <alloca.h>
+#else
+#ifdef _AIX
+ #pragma alloca
+#endif
+#endif
 #include <pwd.h>
 #include <string.h>
 #include <errno.h>
@@ -406,18 +413,17 @@ struct query *ctl;        /* option record to be initialized */
            break;
        case 'r':
        case LA_FOLDER:
-           buf = xmalloc(strlen(optarg));
+           buf = alloca(strlen(optarg));
            strcpy(buf, optarg);
            cp = strtok(buf, ",");
            do {
                save_str(&ctl->mailboxes, cp, 0);
            } while
                ((cp = strtok((char *)NULL, ",")));
-           free(buf);
            break;
        case 'S':
        case LA_SMTPHOST:
-           buf = xmalloc(strlen(optarg));
+           buf = alloca(strlen(optarg));
            strcpy(buf, optarg);
            cp = strtok(buf, ",");
            do {
@@ -425,7 +431,6 @@ struct query *ctl;  /* option record to be initialized */
            } while
                ((cp = strtok((char *)NULL, ",")));
            ocount++;
-           free(buf);
            break;
        case 'D':
        case LA_SMTPADDR:
@@ -433,7 +438,7 @@ struct query *ctl;  /* option record to be initialized */
            break;
        case 'Z':
        case LA_ANTISPAM:
-           buf = xmalloc(strlen(optarg));
+           buf = alloca(strlen(optarg));
            strcpy(buf, optarg);
            cp = strtok(buf, ",");
            do {
@@ -442,7 +447,6 @@ struct query *ctl;  /* option record to be initialized */
                idp->val.status.num = atoi(cp);
            } while
                ((cp = strtok((char *)NULL, ",")));
-           free(buf);
            break;
        case 'b':
        case LA_BATCHLIMIT:
diff --git a/pop3.c b/pop3.c
index 33aa3b49ff6ed46eb136ba249d76ac548ddfa608..7238e345034eb0e01363ca5df7e96324932b7ae9 100644 (file)
--- a/pop3.c
+++ b/pop3.c
@@ -7,6 +7,13 @@
 #include  "config.h"
 #ifdef POP3_ENABLE
 #include  <stdio.h>
+#if defined(HAVE_ALLOCA_H)
+#include <alloca.h>
+#else
+#ifdef _AIX
+ #pragma alloca
+#endif
+#endif
 #include  <string.h>
 #include  <ctype.h>
 #if defined(HAVE_UNISTD_H)
@@ -218,12 +225,11 @@ int pop3_getauth(int sock, struct query *ctl, char *greeting)
            *++end = '\0';
 
        /* copy timestamp and password into digestion buffer */
-       msg = (char *)xmalloc((end-start+1) + strlen(ctl->password) + 1);
+       msg = (char *)alloca((end-start+1) + strlen(ctl->password) + 1);
        strcpy(msg,start);
        strcat(msg,ctl->password);
 
        strcpy(ctl->digest, MD5Digest(msg));
-       free(msg);
 
        ok = gen_transact(sock, "APOP %s %s", ctl->remotename, ctl->digest);
        break;
index 0f0dcf42a81a86dbbdedc0e3759548428781645d..32a4ed720dc7eb2a2bc1cfac3c0fd2f1b495c485 100644 (file)
--- a/unmime.c
+++ b/unmime.c
 
 #include <string.h>
 #include <stdlib.h>
+#if defined(HAVE_ALLOCA_H)
+#include <alloca.h>
+#else
+#ifdef _AIX
+ #pragma alloca
+#endif
+#endif
 #include <ctype.h>
 #include "fetchmail.h"
 
@@ -363,7 +370,7 @@ int MimeBodyType(unsigned char *hdrs, int WantDecode)
       XferEncOfs = NxtHdr;
       p = nxtaddr(NxtHdr);
       if (p != NULL) {
-       XferEnc = (char *)xmalloc(strlen(p) + 1);
+       XferEnc = (char *)alloca(strlen(p) + 1);
        strcpy(XferEnc, p);
        HdrsFound++;
       }
@@ -394,7 +401,7 @@ int MimeBodyType(unsigned char *hdrs, int WantDecode)
       } while ( (p != NULL) && ((*(p+1) == '\t') || (*(p+1) == ' ')) );
       if (p == NULL) p = NxtHdr + strlen(NxtHdr);
 
-      CntType = (char *)xmalloc(p-NxtHdr+2);
+      CntType = (char *)alloca(p-NxtHdr+2);
       strncpy(CntType, NxtHdr, (p-NxtHdr));
       *(CntType+(p-NxtHdr)) = '\0';
       HdrsFound++;
@@ -402,7 +409,7 @@ int MimeBodyType(unsigned char *hdrs, int WantDecode)
     else if (strncasecmp("MIME-Version:", NxtHdr, 13) == 0) {
       p = nxtaddr(NxtHdr);
       if (p != NULL) {
-       MimeVer = (char *)xmalloc(strlen(p) + 1);
+       MimeVer = (char *)alloca(strlen(p) + 1);
        strcpy(MimeVer, p);
        HdrsFound++;
       }
@@ -456,10 +463,6 @@ int MimeBodyType(unsigned char *hdrs, int WantDecode)
 
   }
 
-  if (MimeVer) free(MimeVer);
-  if (XferEnc) free(XferEnc);
-  if (CntType) free(CntType);
-
   return BodyType;
 }