]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug fixes: Multiple bugs in IdleConnList part3
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Thu, 7 Jul 2011 19:08:17 +0000 (22:08 +0300)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Thu, 7 Jul 2011 19:08:17 +0000 (22:08 +0300)
- fix the IdleConnList::closeN to correctly close N connection objects

PS. what an exercise!

src/pconn.cc

index dbbeb4cb4b9f5e431985054267e7fa32a620ec67..006e465df485ff4ad26493a787d713383bbd9b2a 100644 (file)
@@ -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<IdleConnList *>(io.data);
     int index = list->findIndexOf(io.conn);
+    assert(index>=0);
     if (index >= 0) {
         /* might delete list */
         list->removeAt(index);