* fixups, leaks...
authorWilfried Göesgens <willi@citadel.org>
Sun, 17 May 2009 13:49:51 +0000 (13:49 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 17 May 2009 13:49:51 +0000 (13:49 +0000)
webcit/calendar.c
webcit/context_loop.c
webcit/mk_module_init.sh
webcit/serv_func.c
webcit/static.c
webcit/summary.c

index b1e9b9a585af94f2263e32a080f42b0e95f83a57..398fcd538e8085afd8638e7aa6f4a2d4c5c45a69 100644 (file)
@@ -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();
 }
index db6fd289a5afce695f9413237901a664de60e45b..1d1cbb821a39640173b2c9ddf4fcf287a35fe353 100644 (file)
@@ -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);
+
+}
index b46d4e38950c9a8c477b79cbf82725b448828929..61fe9318afba03dae8685ea3e123562aa33ecb18 100755 (executable)
@@ -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 <<EOF  >>$C_FILE
+       free((*sess));
+       (*sess) = NULL;
+}
+
+
+EOF
+
+
 
 
 
+#********************************************************************************
+# DESTROY-Httprequest module logic.
+#********************************************************************************
+cat <<EOF >> $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 <<EOF >> $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 <<EOF >> $H_FILE
+extern void $HOOK(ParsedHttpHdrs *httpreq);
+EOF
+done
 
 cat <<EOF  >>$C_FILE
-       free((*sess));
-       (*sess) = NULL;
 }
-
 EOF
 
 
+
+
+
+
+
 cat <<EOF  >> $H_FILE
 
 #endif /* MODULES_INIT_H */
index 88289bde65adabc9c242d14b94dac00a303fef1a..12e4e5d0c33115dc50ec71d5fba6037b90785b6a 100644 (file)
@@ -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;
 }
index e12a10b298992fc83e60d14619b8627b5f4616c5..0d0eea948b23c423204d232760f887a6ba4bbdc8 100644 (file)
@@ -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;
 }
index 43c8e590dac5bffac585b0ab0115447fa5363ed3..cbc22f6547ed94d28448851dd6b1e567d03b7aba 100644 (file)
@@ -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("<i>");