]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: migrate CachePeer to CBDATA_CLASS API
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 1 Feb 2015 21:25:46 +0000 (13:25 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 1 Feb 2015 21:25:46 +0000 (13:25 -0800)
Replace the alloc/free for CachePeer with new/delete from
the CBDATA_CLASS API.

Shuffle class member default values to constructor.

Shuffle class cleanup code from the (3!) different mechanisms
where it was being done to the class destructor. Also
releasing some memory which was previously leaked on
reconfigure.

Drop the now unused CBDUNL type definition and peerDestroy()
cleanup handler for CachePeer.

src/CachePeer.cc [new file with mode: 0644]
src/CachePeer.h
src/Makefile.am
src/cache_cf.cc
src/neighbors.cc
src/neighbors.h
src/typedefs.h

diff --git a/src/CachePeer.cc b/src/CachePeer.cc
new file mode 100644 (file)
index 0000000..d2589b5
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "acl/Gadgets.h"
+#include "CachePeer.h"
+#include "CachePeerDomainList.h"
+#include "defines.h"
+#include "NeighborTypeDomainList.h"
+#include "pconn.h"
+#include "PeerPoolMgr.h"
+
+CBDATA_CLASS_INIT(CachePeer);
+
+CachePeer::CachePeer() :
+    index(0),
+    name(NULL),
+    host(NULL),
+    type(PEER_NONE),
+    http_port(CACHE_HTTP_PORT),
+    peer_domain(NULL),
+    typelist(NULL),
+    access(NULL),
+    weight(1),
+    basetime(0),
+#if USE_CACHE_DIGESTS
+    digest(NULL),
+    digest_url(NULL),
+#endif
+    tcp_up(0),
+    n_addresses(0),
+    rr_count(0),
+    next(NULL),
+    testing_now(false),
+    login(NULL),
+    connect_timeout(0),
+    connect_fail_limit(0),
+    max_conn(0),
+    domain(NULL),
+#if USE_OPENSSL
+    use_ssl(0),
+    sslcert(NULL),
+    sslkey(NULL),
+    sslversion(0),
+    ssloptions(NULL),
+    sslcipher(NULL),
+    sslcafile(NULL),
+    sslcapath(NULL),
+    sslcrlfile(NULL),
+    sslflags(NULL),
+    ssldomain(NULL),
+    sslContext(NULL),
+    sslSession(NULL),
+#endif
+    front_end_https(0),
+    connection_auth(2 /* auto */)
+{
+    memset(&stats, 0, sizeof(stats));
+    stats.logged_state = PEER_ALIVE;
+
+    memset(&icp, 0, sizeof(icp));
+    icp.port = CACHE_ICP_PORT;
+    icp.version = ICP_VERSION_CURRENT;
+
+#if USE_HTCP
+    memset(&htcp, 0, sizeof(htcp));
+#endif
+    memset(&options, 0, sizeof(options));
+    memset(&mcast, 0, sizeof(mcast));
+    memset(&carp, 0, sizeof(carp));
+#if USE_AUTH
+    memset(&userhash, 0, sizeof(userhash));
+#endif
+    memset(&sourcehash, 0, sizeof(sourcehash));
+
+    standby.pool = NULL;
+    standby.limit = 0;
+    standby.waitingForClose = false;
+}
+
+CachePeer::~CachePeer()
+{
+    xfree(name);
+    xfree(host);
+
+    while (CachePeerDomainList *l = peer_domain) {
+        peer_domain = l->next;
+        xfree(l->domain);
+        xfree(l);
+    }
+
+    while (NeighborTypeDomainList *l = typelist) {
+        typelist = l->next;
+        xfree(l->domain);
+        xfree(l);
+    }
+
+    aclDestroyAccessList(&access);
+
+#if USE_CACHE_DIGESTS
+    cbdataReferenceDone(digest);
+    xfree(digest_url);
+#endif
+
+    delete next;
+
+    xfree(login);
+
+    delete standby.pool;
+
+    // the mgr job will notice that its owner is gone and stop
+    PeerPoolMgr::Checkpoint(standby.mgr, "peer gone");
+
+    xfree(domain);
+
+#if USE_OPENSSL
+    xfree(sslcert);
+    xfree(sslkey);
+    xfree(ssloptions);
+    xfree(sslcipher);
+    xfree(sslcafile);
+    xfree(sslcapath);
+    xfree(sslcrlfile);
+    xfree(sslflags);
+    xfree(ssldomain);
+
+    if (sslContext)
+        SSL_CTX_free(sslContext);
+
+    if (sslSession)
+        SSL_SESSION_free(sslSession);
+#endif
+}
index 7fb82f67e1b8b2d7ed9ee2f729678806a0576ad3..1ab24517849cb888bfb948a5f15a1a6902b4c2b5 100644 (file)
@@ -28,10 +28,14 @@ class PconnPool;
 class PeerDigest;
 class PeerPoolMgr;
 
-// currently a POD
 class CachePeer
 {
+    CBDATA_CLASS(CachePeer);
+
 public:
+    CachePeer();
+    ~CachePeer();
+
     u_int index;
     char *name;
     char *host;
index 9e89a9a6cf59a1a3c619e17a462ec85b358ded65..d5932d5ff2e0a9e924fb8b138a712c4c71995d14 100644 (file)
@@ -286,6 +286,7 @@ squid_SOURCES = \
        cache_manager.cc \
        NeighborTypeDomainList.h \
        CachePeerDomainList.h \
+       CachePeer.cc \
        CachePeer.h \
        CacheManager.h \
        carp.h \
@@ -1400,6 +1401,8 @@ tests_testCacheManager_SOURCES = \
        YesNoNone.cc \
        RefreshPattern.h \
        cache_cf.cc \
+       CachePeer.cc \
+       CachePeer.h \
        CacheDigest.h \
        tests/stub_CacheDigest.cc \
        carp.h \
@@ -1830,6 +1833,8 @@ tests_testEvent_SOURCES = \
        YesNoNone.cc \
        RefreshPattern.h \
        cache_cf.cc \
+       CachePeer.cc \
+       CachePeer.h \
        cache_manager.cc \
        carp.h \
        tests/stub_carp.cc \
@@ -2075,6 +2080,8 @@ tests_testEventLoop_SOURCES = \
        YesNoNone.cc \
        RefreshPattern.h \
        cache_cf.cc \
+       CachePeer.cc \
+       CachePeer.h \
        carp.h \
        tests/stub_carp.cc \
        cbdata.cc \
@@ -2314,6 +2321,8 @@ tests_test_http_range_SOURCES = \
        YesNoNone.cc \
        RefreshPattern.h \
        cache_cf.cc \
+       CachePeer.cc \
+       CachePeer.h \
        cache_manager.cc \
        CacheDigest.h \
        tests/stub_CacheDigest.cc \
@@ -2621,6 +2630,8 @@ tests_testHttpRequest_SOURCES = \
        debug.cc \
        CacheDigest.h \
        tests/stub_CacheDigest.cc \
+       CachePeer.cc \
+       CachePeer.h \
        carp.h \
        tests/stub_carp.cc \
        cbdata.cc \
@@ -3428,6 +3439,8 @@ tests_testURL_SOURCES = \
        tests/stub_cache_manager.cc \
        CacheDigest.h \
        tests/stub_CacheDigest.cc \
+       CachePeer.cc \
+       CachePeer.h \
        carp.h \
        tests/stub_carp.cc \
        cbdata.cc \
index b09fc7783e745a5457596da77a9a7ceb7cf0a42e..3265ec5410ca787fecf78a0bb5a13bb9a4696177 100644 (file)
@@ -133,8 +133,6 @@ static void free_ecap_service_type(Adaptation::Ecap::Config *);
 
 static peer_t parseNeighborType(const char *s);
 
-CBDATA_TYPE(CachePeer);
-
 static const char *const T_MILLISECOND_STR = "millisecond";
 static const char *const T_SECOND_STR = "second";
 static const char *const T_MINUTE_STR = "minute";
@@ -2069,14 +2067,7 @@ static void
 parse_peer(CachePeer ** head)
 {
     char *token = NULL;
-    CachePeer *p;
-    CBDATA_INIT_TYPE_FREECB(CachePeer, peerDestroy);
-    p = cbdataAlloc(CachePeer);
-    p->http_port = CACHE_HTTP_PORT;
-    p->icp.port = CACHE_ICP_PORT;
-    p->weight = 1;
-    p->basetime = 0;
-    p->stats.logged_state = PEER_ALIVE;
+    CachePeer *p = new CachePeer;
 
     if ((token = ConfigParser::NextToken()) == NULL)
         self_destruct();
@@ -2101,7 +2092,6 @@ parse_peer(CachePeer ** head)
         self_destruct();
 
     p->icp.port = GetUdpService();
-    p->connection_auth = 2;    /* auto */
 
     while ((token = ConfigParser::NextToken())) {
         if (!strcmp(token, "proxy-only")) {
@@ -2325,10 +2315,6 @@ parse_peer(CachePeer ** head)
     if (p->connect_fail_limit < 1)
         p->connect_fail_limit = 10;
 
-    p->icp.version = ICP_VERSION_CURRENT;
-
-    p->testing_now = false;
-
 #if USE_CACHE_DIGESTS
 
     if (!p->options.no_digest) {
@@ -2354,21 +2340,8 @@ parse_peer(CachePeer ** head)
 static void
 free_peer(CachePeer ** P)
 {
-    CachePeer *p;
-
-    while ((p = *P) != NULL) {
-        *P = p->next;
-#if USE_CACHE_DIGESTS
-
-        cbdataReferenceDone(p->digest);
-#endif
-
-        // the mgr job will notice that its owner is gone and stop
-        PeerPoolMgr::Checkpoint(p->standby.mgr, "peer gone");
-        delete p->standby.pool;
-        cbdataFree(p);
-    }
-
+    delete *P;
+    *P = NULL;
     Config.npeers = 0;
 }
 
index fde225c9eeea7a3ce6977fedd41dda591eafd415..db443c967857cc4f5707cc066d302a08583537bd 100644 (file)
@@ -522,7 +522,8 @@ neighborRemove(CachePeer * target)
 
     if (p) {
         *P = p->next;
-        cbdataFree(p);
+        p->next = NULL;
+        delete p;
         --Config.npeers;
     }
 
@@ -945,7 +946,7 @@ neighborIgnoreNonPeer(const Ip::Address &from, icp_opcode opcode)
     }
 
     if (np == NULL) {
-        np = (CachePeer *)xcalloc(1, sizeof(CachePeer));
+        np = new CachePeer;
         np->in_addr = from;
         np->icp.port = from.port();
         np->type = PEER_NONE;
@@ -1169,31 +1170,6 @@ neighborUp(const CachePeer * p)
     return 1;
 }
 
-void
-peerDestroy(void *data)
-{
-    CachePeer *p = (CachePeer *)data;
-
-    if (p == NULL)
-        return;
-
-    CachePeerDomainList *nl = NULL;
-
-    for (CachePeerDomainList *l = p->peer_domain; l; l = nl) {
-        nl = l->next;
-        safe_free(l->domain);
-        xfree(l);
-    }
-
-    safe_free(p->host);
-    safe_free(p->name);
-    safe_free(p->domain);
-#if USE_CACHE_DIGESTS
-
-    cbdataReferenceDone(p->digest);
-#endif
-}
-
 void
 peerNoteDigestGone(CachePeer * p)
 {
index 6cb771d8b433a8b3697e70bed5d4e7fbf256dedc..3e9a9f8dfed606f3593027ea5d73446e8565c3c4 100644 (file)
@@ -51,7 +51,6 @@ CachePeer *neighborsDigestSelect(HttpRequest * request);
 void peerNoteDigestLookup(HttpRequest * request, CachePeer * p, lookup_t lookup);
 void peerNoteDigestGone(CachePeer * p);
 int neighborUp(const CachePeer * e);
-CBDUNL peerDestroy;
 const char *neighborTypeStr(const CachePeer * e);
 peer_t neighborType(const CachePeer *, const HttpRequest *);
 void peerConnectFailed(CachePeer *);
index 7d38ff3ae9be9afd52d43ffc60d3318c58c8b405..3856eb7da0cecb3e80300950fd32a4099dc14f98 100644 (file)
@@ -30,7 +30,6 @@ typedef variable_list *(oid_ParseFn) (variable_list *, snint *);
 #endif
 
 typedef void FREE(void *);
-typedef void CBDUNL(void *);
 typedef void FOCB(void *, int fd, int errcode);
 typedef void PF(int, void *);