NETCFG: fix leaks & oddities
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 27 Jan 2013 09:32:51 +0000 (10:32 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 27 Jan 2013 09:32:51 +0000 (10:32 +0100)
citadel/modules/listsub/serv_listsub.c
citadel/netconfig.c

index bc00efa00b24ba956231b9f534bc747ac08edcc5..6c9ed1f743340e114e3f3cf861dcad4b79799ff7 100644 (file)
@@ -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]);
+       }
 }
 
 
index 41aeae6a6d00431df3e0d23370bf8b1f91a505d0..52adbbddff79cdb60730b3893a4c740a42399562 100644 (file)
@@ -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;
                }
        }