]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: convert AclDenyInfoList and AclNameList to MEMPROXY_CLASS
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 24 Oct 2016 12:46:35 +0000 (01:46 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 24 Oct 2016 12:46:35 +0000 (01:46 +1300)
Use the C++ new/delete operators provided by MEMPROXY_CLASS and
associated as-needed pool creation instead of C Alloc/Free
functions and pre-initialized pool.

Remove now unused MEM_ACL_DENY_INFO_LIST and MEM_ACL_NAME_LIST
memory pools.

Remove apparently unused DenyInfoList global.

Fixes a memory leak on shutdown/reconfigure when
aclDestroyDenyInfoList() frees a list of AclDenyInfoList object
but not the AclNameList objects attached to them.

Fixes a memory leak when reconfigure frees a list of AclDenyInfoList
objects but not the URL/page-name strings attached to them.

src/acl/AclDenyInfoList.h
src/acl/AclNameList.h
src/acl/Gadgets.cc
src/cache_cf.cc
src/globals.h
src/mem/forward.h
src/mem/old_api.cc

index e071a7d702acd0e92a6d1dcd75be57d732d45e53..c05311e0b0580cafa162493bd70a0455c485e10e 100644 (file)
@@ -9,18 +9,35 @@
 #ifndef SQUID_ACLDENYINFOLIST_H_
 #define SQUID_ACLDENYINFOLIST_H_
 
+#include "acl/AclNameList.h"
 #include "err_type.h"
-
-class AclNameList;
+#include "errorpage.h"
+#include "mem/forward.h"
 
 /// deny_info representation. Currently a POD.
 class AclDenyInfoList
 {
+    MEMPROXY_CLASS(AclDenyInfoList);
+
 public:
-    err_type err_page_id;
-    char *err_page_name;
-    AclNameList *acl_list;
-    AclDenyInfoList *next;
+    AclDenyInfoList(const char *t) {
+        err_page_name = xstrdup(t);
+        err_page_id = errorReservePageId(t);
+    }
+    ~AclDenyInfoList() {
+        xfree(err_page_name);
+        delete acl_list;
+        while (next) {
+            auto *a = next;
+            next = a->next;
+            a->next = nullptr;
+            delete a;
+        }
+    }
+    err_type err_page_id = ERR_NONE;
+    char *err_page_name = nullptr;
+    AclNameList *acl_list = nullptr;
+    AclDenyInfoList *next = nullptr;
 };
 
 #endif /* SQUID_ACLDENYINFOLIST_H_ */
index ebd625177daabedf9a95648820ad348bf01f47dd..2e514ae5693b3ce6b4780af81196a6abef03f7ef 100644 (file)
 #define SQUID_ACL_ACLNAMELIST_H_
 
 #include "acl/forward.h"
+#include "mem/forward.h"
 
-/// list of name-based ACLs. Currently a POD.
+/// list of name-based ACLs
 class AclNameList
 {
+    MEMPROXY_CLASS(AclNameList);
+
 public:
+    AclNameList(const char *t) {
+        xstrncpy(name, t, ACL_NAME_SZ-1);
+    }
+    ~AclNameList() {
+        // recursion is okay, these lists are short
+        delete next;
+    }
+
     char name[ACL_NAME_SZ];
-    AclNameList *next;
+    AclNameList *next = nullptr;
 };
 // TODO: convert to a std::list<string>
 
index 017ed9c6a54fa3517fc666271a0132b51716fad3..409138a19b159d0e0f9f79a6150dd87c1cb20226 100644 (file)
@@ -19,7 +19,6 @@
 #include "squid.h"
 #include "acl/Acl.h"
 #include "acl/AclDenyInfoList.h"
-#include "acl/AclNameList.h"
 #include "acl/Checklist.h"
 #include "acl/Gadgets.h"
 #include "acl/Strategised.h"
@@ -105,9 +104,8 @@ void
 aclParseDenyInfoLine(AclDenyInfoList ** head)
 {
     char *t = NULL;
-    AclDenyInfoList *A = NULL;
-    AclDenyInfoList *B = NULL;
-    AclDenyInfoList **T = NULL;
+    AclDenyInfoList *B;
+    AclDenyInfoList **T;
     AclNameList *L = NULL;
     AclNameList **Tail = NULL;
 
@@ -119,16 +117,13 @@ aclParseDenyInfoLine(AclDenyInfoList ** head)
         return;
     }
 
-    A = (AclDenyInfoList *)memAllocate(MEM_ACL_DENY_INFO_LIST);
-    A->err_page_id = errorReservePageId(t);
-    A->err_page_name = xstrdup(t);
-    A->next = (AclDenyInfoList *) NULL;
+    AclDenyInfoList *A = new AclDenyInfoList(t);
+
     /* next expect a list of ACL names */
     Tail = &A->acl_list;
 
     while ((t = ConfigParser::NextToken())) {
-        L = (AclNameList *)memAllocate(MEM_ACL_NAME_LIST);
-        xstrncpy(L->name, t, ACL_NAME_SZ-1);
+        L = new AclNameList(t);
         *Tail = L;
         Tail = &L->next;
     }
@@ -136,7 +131,7 @@ aclParseDenyInfoLine(AclDenyInfoList ** head)
     if (A->acl_list == NULL) {
         debugs(28, DBG_CRITICAL, "aclParseDenyInfoLine: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
         debugs(28, DBG_CRITICAL, "aclParseDenyInfoLine: deny_info line contains no ACL's, skipping");
-        memFree(A, MEM_ACL_DENY_INFO_LIST);
+        delete A;
         return;
     }
 
@@ -315,8 +310,7 @@ aclDestroyDenyInfoList(AclDenyInfoList ** list)
         }
 
         a_next = a->next;
-        xfree(a->err_page_name);
-        memFree(a, MEM_ACL_DENY_INFO_LIST);
+        delete a;
     }
 
     *list = NULL;
index 0e191a51b8b71eb3dd11b9bed444e35d7690ad9b..f9777b6825140c8a6322da7cd5720d1e58cca0e0 100644 (file)
@@ -11,7 +11,6 @@
 #include "squid.h"
 #include "acl/Acl.h"
 #include "acl/AclDenyInfoList.h"
-#include "acl/AclNameList.h"
 #include "acl/AclSizeLimit.h"
 #include "acl/Address.h"
 #include "acl/Gadgets.h"
@@ -2363,12 +2362,10 @@ free_cachemgrpasswd(Mgr::ActionPasswordList ** head)
 static void
 dump_denyinfo(StoreEntry * entry, const char *name, AclDenyInfoList * var)
 {
-    AclNameList *a;
-
     while (var != NULL) {
         storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
 
-        for (a = var->acl_list; a != NULL; a = a->next)
+        for (auto *a = var->acl_list; a != NULL; a = a->next)
             storeAppendPrintf(entry, " %s", a->name);
 
         storeAppendPrintf(entry, "\n");
@@ -2386,24 +2383,8 @@ parse_denyinfo(AclDenyInfoList ** var)
 void
 free_denyinfo(AclDenyInfoList ** list)
 {
-    AclDenyInfoList *a = NULL;
-    AclDenyInfoList *a_next = NULL;
-    AclNameList *l = NULL;
-    AclNameList *l_next = NULL;
-
-    for (a = *list; a; a = a_next) {
-        for (l = a->acl_list; l; l = l_next) {
-            l_next = l->next;
-            memFree(l, MEM_ACL_NAME_LIST);
-            l = NULL;
-        }
-
-        a_next = a->next;
-        memFree(a, MEM_ACL_DENY_INFO_LIST);
-        a = NULL;
-    }
-
-    *list = NULL;
+    delete *list;
+    *list = nullptr;
 }
 
 static void
index 2ab7c0ad39d214050fb565e225446f7f64a0032c..35176d609fe75e1d14caca8fe92140fff74e0a39 100644 (file)
@@ -9,7 +9,6 @@
 #ifndef SQUID_GLOBALS_H
 #define SQUID_GLOBALS_H
 
-#include "acl/AclDenyInfoList.h"
 #include "CacheDigest.h"
 #include "defines.h"
 #include "hash.h"
@@ -62,8 +61,6 @@ extern int DnsSocketB;      /* -1 */
 extern int n_disk_objects;  /* 0 */
 extern IoStats IOStats;
 
-extern AclDenyInfoList *DenyInfoList;   /* NULL */
-
 extern struct timeval squid_start;
 extern int starting_up; /* 1 */
 extern int shutting_down;   /* 0 */
index dd0d3af716dba57a7bd4cec07e813ce07716fed7..d7adc846291870ac56e5f0ff8091910c7642a744 100644 (file)
@@ -44,8 +44,6 @@ typedef enum {
     MEM_16K_BUF,
     MEM_32K_BUF,
     MEM_64K_BUF,
-    MEM_ACL_DENY_INFO_LIST,
-    MEM_ACL_NAME_LIST,
     MEM_LINK_LIST,
     MEM_DREAD_CTRL,
     MEM_DWRITE_Q,
index 32e8d6f6e03a94b5f4fd162d019a61ce758f2313..9ce3d444bd3a816b7138f8c6c6c530d245a086f8 100644 (file)
@@ -9,8 +9,6 @@
 /* DEBUG: section 13    High Level Memory Pool Management */
 
 #include "squid.h"
-#include "acl/AclDenyInfoList.h"
-#include "acl/AclNameList.h"
 #include "base/PackableStream.h"
 #include "ClientInfo.h"
 #include "dlink.h"
@@ -442,9 +440,6 @@ Mem::Init(void)
     memDataInit(MEM_16K_BUF, "16K Buffer", 16384, 10, false);
     memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10, false);
     memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10, false);
-    memDataInit(MEM_ACL_DENY_INFO_LIST, "AclDenyInfoList",
-                sizeof(AclDenyInfoList), 0);
-    memDataInit(MEM_ACL_NAME_LIST, "acl_name_list", sizeof(AclNameList), 0);
     memDataInit(MEM_LINK_LIST, "link_list", sizeof(link_list), 10);
     memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0);
     memDataInit(MEM_DWRITE_Q, "dwrite_q", sizeof(dwrite_q), 0);