diff options
author | Timo Teräs <timo.teras@iki.fi> | 2012-04-26 13:41:36 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2012-04-26 13:41:36 +0300 |
commit | 318655679724213db24a9da9d5a5ddba3efe2254 (patch) | |
tree | 73d784ffe32642677ea2a38ca3ba3c09a4618bed /main/squid/squid-3.2-stathist-memleak.patch | |
parent | e2c73b39f5d8235ef6ac14bf4bb66d1b39ec2657 (diff) | |
download | aports-318655679724213db24a9da9d5a5ddba3efe2254.tar.bz2 aports-318655679724213db24a9da9d5a5ddba3efe2254.tar.xz |
main/squid: fix a memory leak
Ref #1054 - this hopefully fixes the bug, but further testing is
needed to verify it. Valgrind traces look optimistic.
Fix authored by me; and reported also to upstream:
http://bugs.squid-cache.org/show_bug.cgi?id=3537
Diffstat (limited to 'main/squid/squid-3.2-stathist-memleak.patch')
-rw-r--r-- | main/squid/squid-3.2-stathist-memleak.patch | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/main/squid/squid-3.2-stathist-memleak.patch b/main/squid/squid-3.2-stathist-memleak.patch new file mode 100644 index 0000000000..261fb934c3 --- /dev/null +++ b/main/squid/squid-3.2-stathist-memleak.patch @@ -0,0 +1,48 @@ +Author: Timo Teras <timo.teras@iki.fi> + +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<capacity_; ++i) +- bins[i]=0; ++ xfree(bins); ++ bins = NULL; + } + + StatHist::StatHist(const StatHist &src) : +@@ -71,7 +71,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)); + } + } +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<bins_type *>(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<bins_type *>(xcalloc(src.capacity_, sizeof(bins_type))); ++ } + min_=src.min_; + max_=src.max_; + scale_=src.scale_; |