* Trying to fix a memory bug somewhere.
authorArt Cancro <ajc@citadel.org>
Sat, 12 Mar 2005 05:42:36 +0000 (05:42 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 12 Mar 2005 05:42:36 +0000 (05:42 +0000)
* While working on the above, noticed that the way we did the per-session
  dynamic symbols loses badly in terms of performance.  Began moving to
  a less modular but better performing way of doing the same.

citadel/ChangeLog
citadel/citadel.h
citadel/serv_imap.c
citadel/serv_imap.h
citadel/serv_pop3.c
citadel/serv_pop3.h
citadel/serv_smtp.c
citadel/server.h
citadel/server_main.c
citadel/stress.c

index 1c5135175a6d99ae32d3eb60bf585b84848504e9..b01230426999dceddb740df057fffd0482ad0c7a 100644 (file)
@@ -1,4 +1,10 @@
  $Log$
+ Revision 641.26  2005/03/12 05:42:35  ajc
+ * Trying to fix a memory bug somewhere.
+ * While working on the above, noticed that the way we did the per-session
+   dynamic symbols loses badly in terms of performance.  Began moving to
+   a less modular but better performing way of doing the same.
+
  Revision 641.25  2005/03/10 03:36:25  ajc
  * Silenced a compiler warning
  * Our graceful cleanup handler no longer gracefully cleans up after
@@ -6535,3 +6541,6 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
+
+
index 2bc0bf3fe8211ef992e761294b2087c8bd22a0b9..918ea2b049b6da795cf7d9e2e5451d0ed5c9e4e0 100644 (file)
@@ -9,6 +9,7 @@
 
 #ifndef CITADEL_H
 #define CITADEL_H
+/* #include <dmalloc.h> uncomment if using dmalloc */
 
 /* Build Citadel with the calendar service only if the header *and*
  * library for libical are both present.
index 7c22d87c405435023ad7750946ffc8272d64fe02..29a541917d846bca01ea42bea6db694e9fbfdd6c 100644 (file)
@@ -344,6 +344,7 @@ void imap_cleanup_function(void)
                IMAP->cached_bodymsgnum = (-1);
        }
 
+       free(IMAP);
        lprintf(CTDL_DEBUG, "Finished IMAP cleanup hook\n");
 }
 
@@ -356,7 +357,7 @@ void imap_greeting(void)
 {
 
        strcpy(CC->cs_clientname, "IMAP session");
-       CtdlAllocUserData(SYM_IMAP, sizeof(struct citimap));
+       IMAP = malloc(sizeof (struct citimap));
        IMAP->authstate = imap_as_normal;
        IMAP->cached_rfc822_data = NULL;
        IMAP->cached_rfc822_msgnum = (-1);
index f98481d47a38288c5a646ebb2fc32d066f523e86..0eb2d28aeef3f349ad8aa58200d0aed634e0e695 100644 (file)
@@ -58,7 +58,7 @@ enum {
 #define IMAP_RECENT            64      /* reportable but not setable */
 
 
-#define IMAP ((struct citimap *)CtdlGetUserData(SYM_IMAP))
+#define IMAP CC->IMAP
 
 /*
  * When loading arrays of message ID's into memory, increase the buffer to
index a613a9415242ec55b139e173a5c69727d810e184..2802fbf505d2d94b9add4a99fb726d48fe26616b 100644 (file)
@@ -76,6 +76,8 @@ void pop3_cleanup_function(void) {
 
        lprintf(CTDL_DEBUG, "Performing POP3 cleanup hook\n");
        if (POP3->msgs != NULL) free(POP3->msgs);
+
+       free(POP3);
 }
 
 
@@ -86,7 +88,7 @@ void pop3_cleanup_function(void) {
 void pop3_greeting(void) {
        strcpy(CC->cs_clientname, "POP3 session");
        CC->internal_pgm = 1;
-       CtdlAllocUserData(SYM_POP3, sizeof(struct citpop3));
+       POP3 = malloc(sizeof(struct citpop3));
        POP3->msgs = NULL;
        POP3->num_msgs = 0;
 
index c2f2bc440568a6c2fd283c115a934d3a7bbc7d0b..8c73f689d0d2bd796c010aecb6e2e30694d2180d 100644 (file)
@@ -20,7 +20,7 @@ struct citpop3 {              /* Information about the current session */
                                 * incremented by one.
                                 */
 
-#define POP3 ((struct citpop3 *)CtdlGetUserData(SYM_POP3))
+#define POP3 CC->POP3
 
 void pop3_cleanup_function(void);
 void pop3_greeting(void);
index 48a3933c3c143b165da4a75de0e74cecc6762db7..9adee16344b88ab2d471c6cf20d5d4fabfc3983f 100644 (file)
@@ -106,9 +106,9 @@ enum {                              /* Delivery modes */
        smtp_deliver_remote
 };
 
-#define SMTP           ((struct citsmtp *)CtdlGetUserData(SYM_SMTP))
-#define SMTP_RECPS     ((char *)CtdlGetUserData(SYM_SMTP_RECPS))
-#define SMTP_ROOMS     ((char *)CtdlGetUserData(SYM_SMTP_ROOMS))
+#define SMTP           CC->SMTP
+#define SMTP_RECPS     CC->SMTP_RECPS
+#define SMTP_ROOMS     CC->SMTP_ROOMS
 
 
 int run_queue_now = 0; /* Set to 1 to ignore SMTP send retry times */
@@ -120,8 +120,6 @@ int run_queue_now = 0;      /* Set to 1 to ignore SMTP send retry times */
 /*****************************************************************************/
 
 
-
-
 /*
  * Here's where our SMTP session begins its happy day.
  */
@@ -130,9 +128,9 @@ void smtp_greeting(void) {
        strcpy(CC->cs_clientname, "SMTP session");
        CC->internal_pgm = 1;
        CC->cs_flags |= CS_STEALTH;
-       CtdlAllocUserData(SYM_SMTP, sizeof(struct citsmtp));
-       CtdlAllocUserData(SYM_SMTP_RECPS, SIZ);
-       CtdlAllocUserData(SYM_SMTP_ROOMS, SIZ);
+       SMTP = malloc(sizeof(struct citsmtp));
+       SMTP_RECPS = malloc(SIZ);
+       SMTP_ROOMS = malloc(SIZ);
        snprintf(SMTP_RECPS, SIZ, "%s", "");
        snprintf(SMTP_ROOMS, SIZ, "%s", "");
 
@@ -1642,6 +1640,23 @@ void smtp_init_spoolout(void) {
 /*****************************************************************************/
 /*                      MODULE INITIALIZATION STUFF                          */
 /*****************************************************************************/
+/*
+ * This cleanup function blows away the temporary memory used by
+ * the SMTP server.
+ */
+void smtp_cleanup_function(void) {
+
+       /* Don't do this stuff if this is not an SMTP session! */
+       if (CC->h_command_function != smtp_command_loop) return;
+
+       lprintf(CTDL_DEBUG, "Performing SMTP cleanup hook\n");
+       free(SMTP);
+       free(SMTP_ROOMS);
+       free(SMTP_RECPS);
+}
+
+
+
 
 
 char *serv_smtp_init(void)
@@ -1674,6 +1689,7 @@ char *serv_smtp_init(void)
 
        smtp_init_spoolout();
        CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);
+       CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP);
        CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
        return "$Id$";
 }
index 05035324d874e7b36c82fd5ef256bd015c902e2a..caa54536306fee4cbc4c3c167bdc5c597f0212a8 100644 (file)
@@ -48,11 +48,6 @@ enum {
        SYM_DESIRED_SECTION,            /* Used by the MIME parser */
        SYM_MA_INFO,                    /* Handles multipart/alternative */
        SYM_CIT_ICAL,                   /* Used by the calendar service */
-       SYM_IMAP,                       /* Used by the IMAP service */
-       SYM_POP3,                       /* Used by the POP3 service */
-       SYM_SMTP,                       /* Used by the SMTP service */
-       SYM_SMTP_RECPS,
-       SYM_SMTP_ROOMS,
        SYM_VCARD,                      /* vCard handling requires this */
        SYM_MAX
 };
@@ -151,6 +146,11 @@ struct CitContext {
 
        /* Dynamically allocated session data */
        struct CtdlSessData *FirstSessData;
+       struct citimap *IMAP;
+       struct citpop3 *POP3;
+       struct citsmtp *SMTP;
+       char *SMTP_RECPS;
+       char *SMTP_ROOMS;
 };
 
 typedef struct CitContext t_context;
index 49bd1be2b749dd928c8dcd1d25c42693306e259d..9e2f1d54782128a3df9c2ccaadec87d498e5fdf7 100644 (file)
@@ -147,7 +147,7 @@ int main(int argc, char **argv)
                "*** Citadel server engine v%d.%02d ***\n",
                (REV_LEVEL/100), (REV_LEVEL%100));
        lprintf(CTDL_NOTICE,
-               "Copyright (C) 1987-2004 by the Citadel development team.\n");
+               "Copyright (C) 1987-2005 by the Citadel development team.\n");
        lprintf(CTDL_NOTICE,
                "This program is distributed under the terms of the GNU "
                "General Public License.\n");
index 7e26c87695c07464aeb793bbc90e8463cdf3addd..5b950ecd6746dfb019348ffdd886685a21721a61 100644 (file)
@@ -352,8 +352,8 @@ int main(int argc, char** argv)
                if (i == 0) sleep(3);
        }
 
-       fprintf(stderr, "Starting in %d seconds\r", n);
-       sleep(n);
+       //fprintf(stderr, "Starting in %d seconds\r", n);
+       //sleep(n);
        fprintf(stderr, "                      \r");
 
        /* Then, signal the conditional they all are waiting on */