From: Timo Teras <> Date: Mon, 4 Jun 2012 10:56:52 +0000 (-0600) Subject: Bug 3537: polish StatHist copy to avoid memory errors X-Git-Tag: SQUID_3_2_0_18~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27c6f398b06b40cfc928e9164d641ecdd5b34e9d;p=thirdparty%2Fsquid.git Bug 3537: polish StatHist copy to avoid memory errors --- diff --git a/src/StatHist.h b/src/StatHist.h index 05db311271..dfcc304ce6 100644 --- a/src/StatHist.h +++ b/src/StatHist.h @@ -130,15 +130,18 @@ 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_) { + 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_; val_in=src.val_in; val_out=src.val_out; - memcpy(bins,src.bins,capacity_*sizeof(*bins)); + if (bins != NULL) + memcpy(bins,src.bins,capacity_*sizeof(*bins)); return *this; }