From: Christos Tsantilas Date: Thu, 7 Jul 2011 19:08:17 +0000 (+0300) Subject: Bug fixes: Multiple bugs in IdleConnList part3 X-Git-Tag: take08~55^2~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dc322e499f8c64aca4b2d5ce8eeb3f6be364b4a;p=thirdparty%2Fsquid.git Bug fixes: Multiple bugs in IdleConnList part3 - fix the IdleConnList::closeN to correctly close N connection objects PS. what an exercise! --- diff --git a/src/pconn.cc b/src/pconn.cc index dbbeb4cb4b..006e465df4 100644 --- a/src/pconn.cc +++ b/src/pconn.cc @@ -120,9 +120,9 @@ IdleConnList::closeN(size_t n) if (n < 1) { debugs(48, 2, HERE << "Nothing to do."); return; - } else if (n < (size_t)count()) { + } else if (n >= (size_t)size_) { debugs(48, 2, HERE << "Closing all entries."); - while (size_ >= 0) { + while (size_ > 0) { const Comm::ConnectionPointer conn = theList_[--size_]; theList_[size_] = NULL; clearHandlers(conn); @@ -130,28 +130,28 @@ IdleConnList::closeN(size_t n) if (parent_) parent_->noteConnectionRemoved(); } - } else { + } else { //if (n < size_) debugs(48, 2, HERE << "Closing " << n << " of " << size_ << " entries."); - size_t index = 0; + size_t index; // ensure the first N entries are closed - while (index < n) { - const Comm::ConnectionPointer conn = theList_[--size_]; - theList_[size_] = NULL; + for(index = 0; index < n; index++) { + const Comm::ConnectionPointer conn = theList_[index]; + theList_[index] = NULL; clearHandlers(conn); conn->close(); if (parent_) parent_->noteConnectionRemoved(); - ++index; } // shuffle the list N down. - for (; index < (size_t)size_; index++) { - theList_[index - n] = theList_[index]; + for (index = 0; index < (size_t)size_ - n; index++) { + theList_[index] = theList_[index + n]; } // ensure the last N entries are unset - while (index < ((size_t)size_) + n) { - theList_[index] = NULL; + while (index < ((size_t)size_)) { + theList_[index++] = NULL; } + size_ -= n; } if (parent_ && size_ == 0) { @@ -303,6 +303,7 @@ IdleConnList::Timeout(const CommTimeoutCbParams &io) debugs(48, 3, HERE << io.conn); IdleConnList *list = static_cast(io.data); int index = list->findIndexOf(io.conn); + assert(index>=0); if (index >= 0) { /* might delete list */ list->removeAt(index);