From dade39dc9ec1d4ab56f14842a162373542e26a67 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 27 Jan 2013 10:32:51 +0100 Subject: [PATCH] NETCFG: fix leaks & oddities --- citadel/modules/listsub/serv_listsub.c | 26 ++++++++++---------------- citadel/netconfig.c | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/citadel/modules/listsub/serv_listsub.c b/citadel/modules/listsub/serv_listsub.c index bc00efa00..6c9ed1f74 100644 --- a/citadel/modules/listsub/serv_listsub.c +++ b/citadel/modules/listsub/serv_listsub.c @@ -79,7 +79,7 @@ int CountThisSubscriber(OneRoomNetCfg *OneRNCfg, StrBuf *email) int found_sub = 0; int i; - for (i = 0; i < sizeof (ActiveSubscribers); i++) + for (i = 0; i < 2; i++) { Line = OneRNCfg->NetConfigs[ActiveSubscribers[i]]; while (Line != NULL) @@ -97,18 +97,6 @@ int CountThisSubscriber(OneRoomNetCfg *OneRNCfg, StrBuf *email) } /* - subpending, - unsubpending, - ignet_push_share, - listrecp, - digestrecp, - pop3client, - rssclient, - participate, - roommailalias, - maxRoomNetCfg - -/ * * Enter a subscription request */ void do_subscribe(StrBuf **room, StrBuf **email, StrBuf **subtype, StrBuf **webpage) { @@ -289,7 +277,7 @@ void do_subscribe(StrBuf **room, StrBuf **email, StrBuf **subtype, StrBuf **webp FMT_RFC822, "Please confirm your list subscription" ); - free(cf_req); + free(pcf_req); cprintf("%d Subscription entered; confirmation request sent\n", CIT_OK); FreeStrBuf(&UrlRoom); @@ -524,7 +512,7 @@ void do_confirm(StrBuf **room, StrBuf **token) { ConfirmType = maxRoomNetCfg; - for (i = 0; i < sizeof (ConfirmSubscribers); i++) + for (i = 0; i < 2; i++) { PrevLine = &OneRNCfg->NetConfigs[ConfirmSubscribers[i]]; Line = *PrevLine; @@ -571,7 +559,7 @@ void do_confirm(StrBuf **room, StrBuf **token) { success = 1; } else if (ConfirmType == unsubpending) { - for (i = 0; i < sizeof (ActiveSubscribers); i++) + for (i = 0; i < 2; i++) { PrevLine = &OneRNCfg->NetConfigs[ActiveSubscribers[i]]; Line = *PrevLine; @@ -634,6 +622,7 @@ void cmd_subs(char *cmdbuf) { Segments[i] = NewStrBufPlain(NULL, StrLength(Segments[0])); StrBufExtract_NextToken(Segments[i], Segments[0], &Pos, '|'); + i++; } if (!strcasecmp(ChrPtr(Segments[1]), "subscribe")) { @@ -655,6 +644,11 @@ void cmd_subs(char *cmdbuf) else { cprintf("%d Invalid command\n", ERROR + ILLEGAL_VALUE); } + + for (; i>=0; i--) + { + FreeStrBuf(&Segments[i]); + } } diff --git a/citadel/netconfig.c b/citadel/netconfig.c index 41aeae6a6..52adbbddf 100644 --- a/citadel/netconfig.c +++ b/citadel/netconfig.c @@ -132,7 +132,10 @@ void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data) { int i; - for (i = 0; i < ThisOne->nSegments; i++) + if (*data == NULL) + return; + + for (i = 0; i < (*data)->nValues; i++) { FreeStrBuf(&(*data)->Value[i]); } @@ -176,12 +179,12 @@ int ReadRoomNetConfigFile(OneRoomNetCfg **pOneRNCfg, char *filename) memset(OneRNCfg, 0, sizeof(OneRoomNetCfg)); *pOneRNCfg = OneRNCfg; Line = NewStrBuf(); + InStr = NewStrBuf(); while (StrBufTCP_read_line(Line, &fd, 0, &ErrStr) >= 0) { if (StrLength(Line) == 0) continue; Pos = NULL; - InStr = NewStrBufPlain(NULL, StrLength(Line)); StrBufExtract_NextToken(InStr, Line, &Pos, '|'); pCfg = GetCfgTypeByStr(SKEY(InStr)); @@ -357,11 +360,18 @@ void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg) RoomNetCfgLine *pNext, *pName; pCfg = GetCfgTypeByEnum(eCfg, CfgIt); - pName= OneRNCfg->NetConfigs[pCfg->C]; + pName= OneRNCfg->NetConfigs[eCfg]; while (pName != NULL) { pNext = pName->next; - pCfg->DeAllocator(pCfg, &pName); + if (pCfg != NULL) + { + pCfg->DeAllocator(pCfg, &pName); + } + else + { + DeleteGenericCfgLine(NULL, &pName); + } pName = pNext; } } -- 2.30.2