From 0c9ed17199b4d9a7146d94fea42c35391582b053 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 12 Mar 2005 05:42:36 +0000 Subject: [PATCH] * 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. --- citadel/ChangeLog | 9 +++++++++ citadel/citadel.h | 1 + citadel/serv_imap.c | 3 ++- citadel/serv_imap.h | 2 +- citadel/serv_pop3.c | 4 +++- citadel/serv_pop3.h | 2 +- citadel/serv_smtp.c | 32 ++++++++++++++++++++++++-------- citadel/server.h | 10 +++++----- citadel/server_main.c | 2 +- citadel/stress.c | 4 ++-- 10 files changed, 49 insertions(+), 20 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 1c5135175..b01230426 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import + + + diff --git a/citadel/citadel.h b/citadel/citadel.h index 2bc0bf3fe..918ea2b04 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -9,6 +9,7 @@ #ifndef CITADEL_H #define CITADEL_H +/* #include uncomment if using dmalloc */ /* Build Citadel with the calendar service only if the header *and* * library for libical are both present. diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index 7c22d87c4..29a541917 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -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); diff --git a/citadel/serv_imap.h b/citadel/serv_imap.h index f98481d47..0eb2d28ae 100644 --- a/citadel/serv_imap.h +++ b/citadel/serv_imap.h @@ -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 diff --git a/citadel/serv_pop3.c b/citadel/serv_pop3.c index a613a9415..2802fbf50 100644 --- a/citadel/serv_pop3.c +++ b/citadel/serv_pop3.c @@ -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; diff --git a/citadel/serv_pop3.h b/citadel/serv_pop3.h index c2f2bc440..8c73f689d 100644 --- a/citadel/serv_pop3.h +++ b/citadel/serv_pop3.h @@ -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); diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index 48a3933c3..9adee1634 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -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$"; } diff --git a/citadel/server.h b/citadel/server.h index 05035324d..caa545363 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -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; diff --git a/citadel/server_main.c b/citadel/server_main.c index 49bd1be2b..9e2f1d547 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -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"); diff --git a/citadel/stress.c b/citadel/stress.c index 7e26c8769..5b950ecd6 100644 --- a/citadel/stress.c +++ b/citadel/stress.c @@ -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 */ -- 2.30.2