Author: Timo Teras Reported upstream: http://bugs.squid-cache.org/show_bug.cgi?id=3537 diff --git a/src/StatHist.cc b/src/StatHist.cc index 9e5d0dd..6aeea49 100644 --- a/src/StatHist.cc +++ b/src/StatHist.cc @@ -62,8 +62,8 @@ StatHist::init(unsigned int newCapacity, hbase_f * val_in_, hbase_f * val_out_, 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 576525d..0dbe783 100644 --- a/src/StatHist.h +++ b/src/StatHist.h @@ -130,9 +130,11 @@ StatHist::operator =(const StatHist & src) { if (this==&src) //handle self-assignment return *this; - xfree(bins); // xfree can handle NULL pointers, no need to check - capacity_=src.capacity_; - bins = static_cast(xcalloc(src.capacity_, sizeof(bins_type))); + if (capacity_ != src.capacity_ || bins == NULL) { + xfree(bins); // xfree can handle NULL pointers, no need to check + capacity_=src.capacity_; + bins = static_cast(xcalloc(src.capacity_, sizeof(bins_type))); + } min_=src.min_; max_=src.max_; scale_=src.scale_;