From adc9f3079beac31291ee9c94d7db00575aa4694e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 17 May 2009 13:49:51 +0000 Subject: [PATCH] * fixups, leaks... --- webcit/calendar.c | 7 ++++--- webcit/context_loop.c | 40 +++++++++++++++++++++++++++--------- webcit/mk_module_init.sh | 44 +++++++++++++++++++++++++++++++++++++--- webcit/serv_func.c | 4 ++++ webcit/static.c | 28 +++++++++++-------------- webcit/summary.c | 2 ++ 6 files changed, 93 insertions(+), 32 deletions(-) diff --git a/webcit/calendar.c b/webcit/calendar.c index b1e9b9a58..398fcd538 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -1044,7 +1044,7 @@ void load_ical_object(long msgnum, int unread, ) { StrBuf *Buf; - StrBuf *Data; + StrBuf *Data = NULL; const char *bptr; int Done = 0; char from[128] = ""; @@ -1127,7 +1127,8 @@ void load_ical_object(long msgnum, int unread, } } case 2: - Data = NewStrBufPlain(NULL, msg4_content_length * 2); + if (Data == NULL) + Data = NewStrBufPlain(NULL, msg4_content_length * 2); if (msg4_content_length > 0) { StrBuf_ServGetBLOBBuffered(Data, msg4_content_length); phase ++; @@ -1157,8 +1158,8 @@ void load_ical_object(long msgnum, int unread, which_kind, CallBack, calv); - FreeStrBuf (&Data); } + FreeStrBuf (&Data); icalmemory_free_ring(); } diff --git a/webcit/context_loop.c b/webcit/context_loop.c index db6fd289a..1d1cbb821 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -265,6 +265,7 @@ int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf) if (Args == NULL) /* whe're not that picky about params... TODO: this will spoil '&' in filenames.*/ Args = strchr(ChrPtr(Hdr->ReqLine), '&'); if (Args != NULL) { + Args ++; /* skip the ? */ Hdr->PlainArgs = NewStrBufPlain( Args, StrLength(Hdr->ReqLine) - @@ -361,6 +362,7 @@ int ReadHTTPRequset (ParsedHttpHdrs *Hdr) pch ++; StrBufCutLeft(Line, pch - pchs); StrBufAppendBuf(LastLine, Line, 0); + FreeStrBuf(&Line); continue; } @@ -555,10 +557,24 @@ void context_loop(int *sock) session_attach_modules(TheSession); session_loop(); /* do transaction */ + + + /* How long did this transaction take? */ + gettimeofday(&tx_finish, NULL); + + lprintf(9, "Transaction [%s] completed in %ld.%06ld seconds.\n", + ChrPtr(Hdr.this_page), + ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000, + ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000 + ); + session_detach_modules(TheSession); TheSession->Hdr = NULL; pthread_mutex_unlock(&TheSession->SessionMutex); /* unbind */ + + + http_destroy_modules(&Hdr); /* TODO FreeStrBuf(&c_username); @@ -568,16 +584,8 @@ void context_loop(int *sock) FreeStrBuf(&c_httpauth_pass); */ /* Free the request buffer */ - ///DeleteHash(&HTTPHeaders); ///FreeStrBuf(&ReqLine); - /* How long did this transaction take? */ - gettimeofday(&tx_finish, NULL); - - lprintf(9, "Transaction completed in %ld.%06ld seconds.\n", - ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000, - ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000 - ); } void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP) @@ -844,7 +852,19 @@ InitModule_CONTEXT WebcitAddUrlHandler(HKEY("blank"), blank_page, ANONYMOUS|BOGUS); - WebcitAddUrlHandler(HKEY("blank"), blank_page, URLNAMESPACE); + WebcitAddUrlHandler(HKEY("webcit"), blank_page, URLNAMESPACE); } -//FreeStrBuf(&WCC->this_page); + + +void +HttpDestroyModule_CONTEXT +(ParsedHttpHdrs *httpreq) +{ + FreeStrBuf(&httpreq->ReqLine); + FreeStrBuf(&httpreq->ReadBuf); + FreeStrBuf(&httpreq->PlainArgs); + FreeStrBuf(&httpreq->this_page); + DeleteHash(&httpreq->HTTPHeaders); + +} diff --git a/webcit/mk_module_init.sh b/webcit/mk_module_init.sh index b46d4e389..61fe9318a 100755 --- a/webcit/mk_module_init.sh +++ b/webcit/mk_module_init.sh @@ -43,6 +43,8 @@ SESS_ATTACH_FUNCS=`grep SessionAttachModule_ *.c |sed "s;.*:;;" |sort -u` SESS_DETACH_FUNCS=`grep SessionDetachModule_ *.c |sed "s;.*:;;" |sort -u` SESS_DESTROY_FUNCS=`grep SessionDestroyModule_ *.c |sed "s;.*:;;" |sort -u` +HTTP_DESTROY_FUNCS=`grep HttpDestroyModule_ *.c |sed "s;.*:;;" |sort -u` + #SESS_NEW_FUNCS=`grep SessionNewModule_ *.c |sed "s;.*:;;" |sort -u` @@ -76,6 +78,8 @@ void session_attach_modules (wcsession *sess); void session_detach_modules (wcsession *sess); void session_destroy_modules (wcsession **sess); +void http_destroy_modules (ParsedHttpHdrs *httpreq); + /* @@ -353,18 +357,52 @@ EOF done +cat <>$C_FILE + free((*sess)); + (*sess) = NULL; +} + + +EOF + + +#******************************************************************************** +# DESTROY-Httprequest module logic. +#******************************************************************************** +cat <> $C_FILE + +void http_destroy_modules (ParsedHttpHdrs *httpreq) +{ +EOF + +for HOOK in $HTTP_DESTROY_FUNCS; do +HOOKNAME=`echo $HOOK |sed "s;HttpDestroyModule_;;"` +# Add this entry point to the .c file +cat <> $C_FILE +#ifdef DBG_PRINNT_HOOKS_AT_START + lprintf (CTDL_INFO, "Destructing $HOOKNAME\n"); +#endif + $HOOK(httpreq); +EOF +# Add this entry point to the .h file +cat <> $H_FILE +extern void $HOOK(ParsedHttpHdrs *httpreq); +EOF +done cat <>$C_FILE - free((*sess)); - (*sess) = NULL; } - EOF + + + + + cat <> $H_FILE #endif /* MODULES_INIT_H */ diff --git a/webcit/serv_func.c b/webcit/serv_func.c index 88289bde6..12e4e5d0c 100644 --- a/webcit/serv_func.c +++ b/webcit/serv_func.c @@ -234,6 +234,7 @@ int GetConnected (void) wprintf(_("This server is already serving its maximum number of users and cannot accept any additional logins at this time. Please try again later or contact your system administrator.")); end_burst(); end_webcit_session(); + FreeStrBuf(&Buf); return 1; } @@ -261,6 +262,7 @@ int GetConnected (void) hprintf("Content-type: text/plain; charset=utf-8\r\n"); end_burst(); end_webcit_session(); + FreeStrBuf(&Buf); return 1; } if (WCC->serv_info->serv_rev_level < MINIMUM_CIT_VERSION) { @@ -279,8 +281,10 @@ int GetConnected (void) hprintf("Content-type: text/plain; charset=utf-8\r\n"); end_burst(); end_webcit_session(); + FreeStrBuf(&Buf); return 1; } + FreeStrBuf(&Buf); } return 0; } diff --git a/webcit/static.c b/webcit/static.c index e12a10b29..0d0eea948 100644 --- a/webcit/static.c +++ b/webcit/static.c @@ -105,7 +105,7 @@ void output_static(const char *what) fd = open(what, O_RDONLY); if (fd <= 0) { - lprintf(9, "output_static('%s') -- NOT FOUND --\n", what); + lprintf(9, "output_static('%s') [%s] -- NOT FOUND --\n", what, ChrPtr(WC->Hdr->this_page)); hprintf("HTTP/1.1 404 %s\r\n", strerror(errno)); hprintf("Content-Type: text/plain\r\n"); wprintf("Cannot open %s: %s\r\n", what, strerror(errno)); @@ -175,29 +175,26 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) { char dirname[PATH_MAX]; char reldir[PATH_MAX]; - StrBuf *FileName; - StrBuf *Tag; - StrBuf *Dir; - StrBuf *WebDir; - StrBuf *OneWebName; + StrBuf *FileName = NULL; + StrBuf *Dir = NULL; + StrBuf *WebDir = NULL; + StrBuf *OneWebName = NULL; DIR *filedir = NULL; struct dirent d; struct dirent *filedir_entry; int d_namelen; int d_without_ext; - Dir = NewStrBufPlain(DirName, -1); - WebDir = NewStrBufPlain(RelDir, -1); - OneWebName = NewStrBuf(); filedir = opendir (DirName); if (filedir == NULL) { - FreeStrBuf(&Dir); return 0; } - FileName = NewStrBuf(); - Tag = NewStrBuf(); - while ((readdir_r(filedir, &d, &filedir_entry) == 0) && + Dir = NewStrBufPlain(DirName, -1); + WebDir = NewStrBufPlain(RelDir, -1); + OneWebName = NewStrBuf(); + + while ((readdir_r(filedir, &d, &filedir_entry) == 0) && (filedir_entry != NULL)) { char *PStart; @@ -249,7 +246,7 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) StrBufAppendBufPlain(OneWebName, filedir_entry->d_name, d_namelen, 0); Put(DirList, SKEY(OneWebName), FileName, HFreeStrBuf); - printf("[%s | %s] \n", ChrPtr(OneWebName), ChrPtr(FileName)); +/* printf("[%s | %s] \n", ChrPtr(OneWebName), ChrPtr(FileName));*/ break; default: break; @@ -258,9 +255,8 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) } closedir(filedir); - FreeStrBuf(&FileName); - FreeStrBuf(&Tag); FreeStrBuf(&Dir); + FreeStrBuf(&WebDir); FreeStrBuf(&OneWebName); return 1; } diff --git a/webcit/summary.c b/webcit/summary.c index 43c8e590d..cbc22f654 100644 --- a/webcit/summary.c +++ b/webcit/summary.c @@ -101,6 +101,7 @@ void tasks_section(void) { Msg = (message_summary*) vMsg; display_task(Msg, 0); } + DeleteHashPos(&at); } if (calendar_summary_view() < 1) { @@ -143,6 +144,7 @@ void calendar_section(void) { Msg = (message_summary*) vMsg; load_calendar_item(Msg, 0, &c); } + DeleteHashPos(&at); } if (calendar_summary_view() < 1) { wprintf(""); -- 2.30.2