From: Timo Teras Date: Mon, 21 May 2012 03:59:19 +0000 (-0600) Subject: Bug 3537: statistics histogram leaks memory X-Git-Tag: SQUID_3_2_0_18~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a691fd53b8cd765f7cdbe55ee3b6a936004ee10a;p=thirdparty%2Fsquid.git Bug 3537: statistics histogram leaks memory --- diff --git a/src/StatHist.cc b/src/StatHist.cc index 9e5d0ddcc1..a56c547d79 100644 --- a/src/StatHist.cc +++ b/src/StatHist.cc @@ -59,19 +59,12 @@ StatHist::init(unsigned int newCapacity, hbase_f * val_in_, hbase_f * val_out_, scale_ = capacity_ / val_in(max_ - min_); } -void -StatHist::clear() -{ - for (unsigned int i=0; i(xcalloc(src.capacity_, sizeof(int))); + bins = static_cast(xcalloc(src.capacity_, sizeof(bins_type))); memcpy(bins,src.bins,capacity_*sizeof(*bins)); } } diff --git a/src/StatHist.h b/src/StatHist.h index 576525d21a..05db311271 100644 --- a/src/StatHist.h +++ b/src/StatHist.h @@ -57,7 +57,7 @@ public: */ StatHist(); StatHist(const StatHist&); //not needed - ~StatHist(); + ~StatHist() { clear(); }; typedef uint64_t bins_type; @@ -148,12 +148,12 @@ StatHist::StatHist() : scale_(1.0), val_in(NULL), val_out(NULL) {} -inline -StatHist::~StatHist() +inline void +StatHist::clear() { - xfree(bins); //can handle case of bins being NULL + xfree(bins); // can handle case of bins being NULL bins=NULL; - capacity_=0; //mark as destructed, may be needed for troubleshooting + capacity_=0; // mark as destructed, may be needed for troubleshooting } #endif /* STATHIST_H_ */ diff --git a/src/tests/stub_StatHist.cc b/src/tests/stub_StatHist.cc index cf0cfdfd4e..f3d70947d3 100644 --- a/src/tests/stub_StatHist.cc +++ b/src/tests/stub_StatHist.cc @@ -24,10 +24,6 @@ double statHistDeltaPctile(const StatHist & A, const StatHist & B, double pctile) STUB_RETVAL(0.0) -void -StatHist::clear() -STUB - void StatHist::logInit(unsigned int i, double d1, double d2) STUB