]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3537: statistics histogram leaks memory
authorTimo Teras <timo.teras@iki.fi>
Sat, 12 May 2012 03:48:02 +0000 (21:48 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 12 May 2012 03:48:02 +0000 (21:48 -0600)
src/StatHist.cc
src/StatHist.h

index 9e5d0ddcc1bfe6383a51599c8f1650468f562cf8..422ea742ce8a9df465a8cf9ca00f82e867edbd4a 100644 (file)
@@ -62,8 +62,9 @@ StatHist::init(unsigned int newCapacity, hbase_f * val_in_, hbase_f * val_out_,
 void
 StatHist::clear()
 {
-    for (unsigned int i=0; i<capacity_; ++i)
-        bins[i]=0;
+    xfree(bins); // can handle case of bins being NULL
+    bins=NULL;
+    capacity_=0; // mark as destructed, may be needed for troubleshooting
 }
 
 StatHist::StatHist(const StatHist &src) :
@@ -71,7 +72,7 @@ StatHist::StatHist(const StatHist &src) :
         scale_(src.scale_), val_in(src.val_in), val_out(src.val_out)
 {
     if (src.bins!=NULL) {
-        bins = static_cast<bins_type *>(xcalloc(src.capacity_, sizeof(int)));
+        bins = static_cast<bins_type *>(xcalloc(src.capacity_, sizeof(bins_type)));
         memcpy(bins,src.bins,capacity_*sizeof(*bins));
     }
 }
index 576525d21a16d348cc085e9a8fbbc914e4d30dbd..b422ce7ba7335a8b9917ce6a832241652af9357d 100644 (file)
@@ -57,7 +57,7 @@ public:
      */
     StatHist();
     StatHist(const StatHist&); //not needed
-    ~StatHist();
+    ~StatHist() { clear(); };
 
     typedef uint64_t bins_type;
 
@@ -148,12 +148,4 @@ StatHist::StatHist() :
         scale_(1.0), val_in(NULL), val_out(NULL)
 {}
 
-inline
-StatHist::~StatHist()
-{
-    xfree(bins); //can handle case of bins being NULL
-    bins=NULL;
-    capacity_=0; //mark as destructed, may be needed for troubleshooting
-}
-
 #endif /* STATHIST_H_ */