From: Francesco Chemolli Date: Fri, 2 Jan 2015 15:46:35 +0000 (+0100) Subject: Interim: removed needless spacing and c++ guards, started fixing DelayTagged accessin... X-Git-Tag: merge-candidate-3-v1~384^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f5dc42375b865f251ae4458d9ea77c7e97a76fc7;p=thirdparty%2Fsquid.git Interim: removed needless spacing and c++ guards, started fixing DelayTagged accessing SplayNodes, prevented Splay leaks on several ACL types --- diff --git a/include/splay.h b/include/splay.h index 4f5455e6bc..21719c3265 100644 --- a/include/splay.h +++ b/include/splay.h @@ -9,18 +9,13 @@ #ifndef SQUID_SPLAY_H #define SQUID_SPLAY_H -#if defined(__cplusplus) - #include "fatal.h" - #include - // private class of Splay. Do not use directly template class SplayNode { - public: typedef V Value; typedef int SPLAYCMP(Value const &a, Value const &b); @@ -60,7 +55,6 @@ class SplayIterator; template class Splay { - public: typedef V Value; typedef int SPLAYCMP(Value const &a, Value const &b); @@ -69,7 +63,6 @@ public: typedef const SplayConstIterator const_iterator; Splay():head(NULL), elements (0) {} - mutable SplayNode * head; template Value const *find (FindValue const &, int( * compare)(FindValue const &a, Value const &b)) const; void insert(Value const &, SPLAYCMP *compare); @@ -94,6 +87,8 @@ public: template void visit(Visitor &v) const; size_t elements; +private: + mutable SplayNode * head; }; SQUIDCEXTERN int splayLastResult; @@ -492,7 +487,5 @@ SplayConstIterator::operator * () const return toVisit.top()->data; } -#endif /* cplusplus */ - #endif /* SQUID_SPLAY_H */ diff --git a/src/DelayTagged.cc b/src/DelayTagged.cc index 7d1c764dcc..4d01d1c48a 100644 --- a/src/DelayTagged.cc +++ b/src/DelayTagged.cc @@ -40,7 +40,7 @@ static Splay::SPLAYFREE DelayTaggedFree; DelayTagged::~DelayTagged() { DelayPools::deregisterForUpdates (this); - buckets.head->destroy (DelayTaggedFree); + buckets->destroy (DelayTaggedFree); } static Splay::SPLAYCMP DelayTaggedCmp; @@ -56,11 +56,13 @@ void DelayTaggedFree(DelayTaggedBucket::Pointer &) {} -void -DelayTaggedStatsWalkee(DelayTaggedBucket::Pointer const ¤t, void *state) -{ - current->stats ((StoreEntry *)state); -} +struct DelayTaggedStatsVisitor { + StoreEntry *sentry; + explicit DelayTaggedStatsVisitor(StoreEntry *se) sentry(se) {} + void operator() (DelayTaggedBucket::Pointer const ¤t) { + current->stats(sentry); + } +}; void DelayTagged::stats(StoreEntry * sentry) @@ -72,12 +74,13 @@ DelayTagged::stats(StoreEntry * sentry) storeAppendPrintf(sentry, "\t\tCurrent: "); - if (!buckets.head) { + if (buckets.empty()) { storeAppendPrintf (sentry, "Not used yet.\n\n"); return; } - buckets.head->walk(DelayTaggedStatsWalkee, sentry); + DelayTaggedStatsVisitor visitor(sentry); + buckets.visit(visitor); storeAppendPrintf(sentry, "\n\n"); } diff --git a/src/acl/Arp.cc b/src/acl/Arp.cc index 0d5520b154..5eae6100b4 100644 --- a/src/acl/Arp.cc +++ b/src/acl/Arp.cc @@ -41,8 +41,10 @@ ACLARP::ACLARP (ACLARP const & old) : data (NULL), class_ (old.class_) ACLARP::~ACLARP() { - if (data) + if (data) { data->destroy(); + delete data; + } } char const * diff --git a/src/acl/DomainData.cc b/src/acl/DomainData.cc index 13b23d3df0..733bd1b15d 100644 --- a/src/acl/DomainData.cc +++ b/src/acl/DomainData.cc @@ -25,8 +25,10 @@ xRefFree(T &thing) ACLDomainData::~ACLDomainData() { - if (domains) + if (domains) { domains->destroy(xRefFree); + delete domains; + } } template diff --git a/src/acl/Eui64.cc b/src/acl/Eui64.cc index 678d9d228e..d18e73a4fe 100644 --- a/src/acl/Eui64.cc +++ b/src/acl/Eui64.cc @@ -41,8 +41,10 @@ ACLEui64::ACLEui64 (ACLEui64 const & old) : data (NULL), class_ (old.class_) ACLEui64::~ACLEui64() { - if (data) + if (data) { data->destroy(); + delete data; + } } char const * diff --git a/src/acl/HttpStatus.cc b/src/acl/HttpStatus.cc index b55ef528d2..d83d7de4dc 100644 --- a/src/acl/HttpStatus.cc +++ b/src/acl/HttpStatus.cc @@ -74,8 +74,10 @@ ACLHTTPStatus::ACLHTTPStatus (ACLHTTPStatus const & old) : data(NULL), class_ (o ACLHTTPStatus::~ACLHTTPStatus() { - if (data) + if (data) { data->destroy(); + delete data; + } } char const * diff --git a/src/acl/Ip.cc b/src/acl/Ip.cc index 22484d9b8c..7fc37a9b5b 100644 --- a/src/acl/Ip.cc +++ b/src/acl/Ip.cc @@ -493,8 +493,10 @@ ACLIP::parse() ACLIP::~ACLIP() { - if (data) + if (data) { data->destroy(); + delete data; + } } struct IpAclDumpVisitor { diff --git a/src/acl/StringData.cc b/src/acl/StringData.cc index 778f951aad..7775b7cfd9 100644 --- a/src/acl/StringData.cc +++ b/src/acl/StringData.cc @@ -31,8 +31,10 @@ xRefFree(T &thing) ACLStringData::~ACLStringData() { - if (values) + if (values) { values->destroy(xRefFree); + delete values; + } } static int diff --git a/src/acl/UserData.cc b/src/acl/UserData.cc index 638f05e72b..c27a37ade1 100644 --- a/src/acl/UserData.cc +++ b/src/acl/UserData.cc @@ -24,8 +24,10 @@ xRefFree(T &thing) ACLUserData::~ACLUserData() { - if (names) + if (names) { names->destroy(xRefFree); + delete names; + } } static int