From: Wilfried Goesgens Date: Sun, 5 Jun 2011 13:49:09 +0000 (+0000) Subject: Free all our allocated resources after notifying / sending a http request. X-Git-Tag: v8.11~1049 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=75b5384185328d4e7be3c29d5f9527a39aede0dd Free all our allocated resources after notifying / sending a http request. --- diff --git a/citadel/modules/eventclient/serv_eventclient.c b/citadel/modules/eventclient/serv_eventclient.c index 873d16628..f2fbef00a 100644 --- a/citadel/modules/eventclient/serv_eventclient.c +++ b/citadel/modules/eventclient/serv_eventclient.c @@ -153,9 +153,15 @@ gotstatus(evcurl_global_data *global, int nnrun) msta = curl_multi_remove_handle(mhnd, chnd); if (msta) CtdlLogPrintf(CTDL_ERR, "EVCURL: warning problem detaching completed handle from curl multi: %s\n", curl_multi_strerror(msta)); + IO->HttpReq.attached = 0; IO->SendDone(IO); - curl_multi_cleanup(msta); + curl_easy_cleanup(IO->HttpReq.chnd); + curl_slist_free_all(IO->HttpReq.headers); + FreeStrBuf(&IO->HttpReq.ReplyData); + FreeURL(&IO->ConnectMe); + RemoveContext(IO->CitContext); + free(IO); } } } @@ -235,6 +241,7 @@ gotwatchsock(CURL *easy, curl_socket_t fd, int action, void *cglobal, void *csoc } if (CURL_POLL_REMOVE == action) { CtdlLogPrintf(CTDL_ERR,"EVCURL: called last time to unregister this sockwatcher\n"); + ev_io_stop(event_base, &sockwatcher->ioev); free(sockwatcher); } else { int events = (action & CURL_POLL_IN ? EV_READ : 0) | (action & CURL_POLL_OUT ? EV_WRITE : 0); @@ -383,6 +390,10 @@ static void WakeupCurlCallback(EV_P_ ev_async *w, int revents) curl_multi_perform(&global, CURL_POLL_NONE); } +static void evcurl_shutdown (void) +{ + curl_multi_cleanup(global.mhnd); +} /***************************************************************************** * libevent integration * *****************************************************************************/ @@ -484,7 +495,7 @@ void *client_event_thread(void *arg) DeleteHash(&InboundEventQueues[0]); DeleteHash(&InboundEventQueues[1]); citthread_mutex_destroy(&EventQueueMutex); - + evcurl_shutdown(); return(NULL); } diff --git a/citadel/modules/extnotify/extnotify.h b/citadel/modules/extnotify/extnotify.h index 63a8fcd8e..efe6b9136 100644 --- a/citadel/modules/extnotify/extnotify.h +++ b/citadel/modules/extnotify/extnotify.h @@ -36,6 +36,7 @@ typedef enum _eNotifyType { typedef struct _NotifyContext { StrBuf **NotifyHostList; + int nNotifyHosts; HashList *NotifyErrors; AsyncIO IO; } NotifyContext; diff --git a/citadel/modules/extnotify/extnotify_main.c b/citadel/modules/extnotify/extnotify_main.c index b26284af5..5ab54c2c7 100644 --- a/citadel/modules/extnotify/extnotify_main.c +++ b/citadel/modules/extnotify/extnotify_main.c @@ -92,7 +92,7 @@ StrBuf* GetNHBuf(int i, int allocit, StrBuf **NotifyHostList) } -StrBuf** GetNotifyHosts(void) +int GetNotifyHosts(NotifyContext *Ctx) { char NotifyHostsBuf[SIZ]; StrBuf *Host; @@ -101,22 +101,20 @@ StrBuf** GetNotifyHosts(void) int notify; const char *pchs, *pche; const char *NextHost = NULL; - StrBuf **NotifyHostList; - int num_notify; /* See if we have any Notification Hosts configured */ - num_notify = get_hosts(NotifyHostsBuf, "notify"); - if (num_notify < 1) - return(NULL); + Ctx->nNotifyHosts = get_hosts(NotifyHostsBuf, "notify"); + if (Ctx->nNotifyHosts < 1) + return 0; - NotifyHostList = malloc(sizeof(StrBuf*) * 2 * (num_notify + 1)); - memset(NotifyHostList, 0, sizeof(StrBuf*) * 2 * (num_notify + 1)); + Ctx->NotifyHostList = malloc(sizeof(StrBuf*) * 2 * (Ctx->nNotifyHosts + 1)); + memset(Ctx->NotifyHostList, 0, sizeof(StrBuf*) * 2 * (Ctx->nNotifyHosts + 1)); NotifyBuf = NewStrBufPlain(NotifyHostsBuf, -1); /* get all configured notifiers's */ - for (notify=0; notifynNotifyHosts; notify++) { - Host = GetNHBuf(notify * 2, 1, NotifyHostList); + Host = GetNHBuf(notify * 2, 1, Ctx->NotifyHostList); StrBufExtract_NextToken(Host, NotifyBuf, &NextHost, '|'); pchs = ChrPtr(Host); pche = strchr(pchs, ':'); @@ -126,11 +124,12 @@ StrBuf** GetNotifyHosts(void) pchs); continue; } - File = GetNHBuf(notify * 2 + 1, 1, NotifyHostList); + File = GetNHBuf(notify * 2 + 1, 1, Ctx->NotifyHostList); StrBufPlain(File, pchs, pche - pchs); StrBufCutLeft(Host, pche - pchs + 1); } - return NotifyHostList; + FreeStrBuf(&NotifyBuf); + return Ctx->nNotifyHosts; } @@ -183,6 +182,7 @@ eNotifyType extNotify_getConfigMessage(char *username, char **PagerNumber, char } } + free(msglist); if (msg == NULL) return eNone; @@ -302,7 +302,7 @@ void process_notify(long NotifyMsgnum, void *usrdata) StrBuf *File; StrBuf *FileBuf = NewStrBuf(); - while(1) + for (i = 0; i < Ctx->nNotifyHosts; i++) { URL = GetNHBuf(i*2, 0, Ctx->NotifyHostList); @@ -327,7 +327,6 @@ void process_notify(long NotifyMsgnum, void *usrdata) msg->cm_fields['I'], msgnum, NULL); - i++; } FreeStrBuf(&FileBuf); } @@ -365,11 +364,9 @@ void process_notify(long NotifyMsgnum, void *usrdata) */ void do_extnotify_queue(void) { - CitContext *CCC = CC; - NotifyContext Ctx; static int doing_queue = 0; - //int i = 0; + int i = 0; /* * This is a simple concurrency check to make sure only one queue run @@ -396,16 +393,29 @@ void do_extnotify_queue(void) CtdlLogPrintf(CTDL_DEBUG, "serv_extnotify: processing notify queue\n"); memset(&Ctx, 0, sizeof(NotifyContext)); - Ctx.NotifyHostList = GetNotifyHosts(); - if (CtdlGetRoom(&CC->room, FNBL_QUEUE_ROOM) != 0) { + if ((GetNotifyHosts(&Ctx) > 0) && + (CtdlGetRoom(&CC->room, FNBL_QUEUE_ROOM) != 0)) + { CtdlLogPrintf(CTDL_ERR, "Cannot find room <%s>\n", FNBL_QUEUE_ROOM); CtdlClearSystemContext(); + if (Ctx.nNotifyHosts > 0) + { + for (i = 0; i < Ctx.nNotifyHosts * 2; i++) + FreeStrBuf(&Ctx.NotifyHostList[i]); + free(Ctx.NotifyHostList); + } return; } CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, process_notify, &Ctx); CtdlLogPrintf(CTDL_DEBUG, "serv_extnotify: queue run completed\n"); doing_queue = 0; + if (Ctx.nNotifyHosts > 0) + { + for (i = 0; i < Ctx.nNotifyHosts * 2; i++) + FreeStrBuf(&Ctx.NotifyHostList[i]); + free(Ctx.NotifyHostList); + } } diff --git a/citadel/modules/extnotify/funambol65.c b/citadel/modules/extnotify/funambol65.c index 6049b179d..38499fafc 100644 --- a/citadel/modules/extnotify/funambol65.c +++ b/citadel/modules/extnotify/funambol65.c @@ -67,6 +67,7 @@ int notify_http_server(char *remoteurl, char *SOAPMessage = NULL; char *contenttype = NULL; StrBuf *ReplyBuf; + StrBuf *Buf; CURL *chnd; AsyncIO *IO; @@ -145,7 +146,9 @@ int notify_http_server(char *remoteurl, IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers, "Pragma: no-cache"); } - ParseURL(&IO->ConnectMe, NewStrBufPlain (remoteurl, -1), 80); + Buf = NewStrBufPlain (remoteurl, -1); + ParseURL(&IO->ConnectMe, Buf, 80); + FreeStrBuf(&Buf); /* TODO: this is uncool... */ CurlPrepareURL(IO->ConnectMe); if (! evcurl_init(IO, // Ctx,