]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: refactor FwdState pinned connection handling slightly
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 10 Aug 2016 00:56:30 +0000 (12:56 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 10 Aug 2016 00:56:30 +0000 (12:56 +1200)
Don't try to be too smart with indirect serverConn == NULL details. It
just confuses static analysis.

This code ordering should resolve the false positive Coverity Scan
issue 740373 and let any real problem show through.

src/FwdState.cc

index 3390a2365042a66119072522d74b508cc73e459e..c78019202a88c05388bc671f0ab284a23aed1e35 100644 (file)
@@ -847,27 +847,29 @@ FwdState::connectStart()
         ConnStateData *pinned_connection = request->pinnedConnection();
         debugs(17,7, "pinned peer connection: " << pinned_connection);
         // pinned_connection may become nil after a pconn race
-        if (pinned_connection)
+        if (pinned_connection) {
             serverConn = pinned_connection->borrowPinnedConnection(request, serverDestinations[0]->getPeer());
-        else
-            serverConn = NULL;
-        if (Comm::IsConnOpen(serverConn)) {
-            pinned_connection->stopPinnedConnectionMonitoring();
-            flags.connected_okay = true;
-            ++n_tries;
-            request->flags.pinned = true;
-            if (pinned_connection->pinnedAuth())
-                request->flags.auth = true;
-
-            closeHandler = comm_add_close_handler(serverConn->fd,  fwdServerClosedWrapper, this);
-
-            syncWithServerConn(pinned_connection->pinning.host);
-
-            // the server may close the pinned connection before this request
-            pconnRace = racePossible;
-            dispatch();
-            return;
-        }
+            if (Comm::IsConnOpen(serverConn)) {
+                pinned_connection->stopPinnedConnectionMonitoring();
+                flags.connected_okay = true;
+                ++n_tries;
+                request->flags.pinned = true;
+                if (pinned_connection->pinnedAuth())
+                    request->flags.auth = true;
+
+                closeHandler = comm_add_close_handler(serverConn->fd,  fwdServerClosedWrapper, this);
+
+                syncWithServerConn(pinned_connection->pinning.host);
+
+                // the server may close the pinned connection before this request
+                pconnRace = racePossible;
+                dispatch();
+                return;
+            }
+
+        } else
+            serverConn = nullptr;
+
         // Pinned connection failure.
         debugs(17,2,HERE << "Pinned connection failed: " << pinned_connection);
         ErrorState *anErr = new ErrorState(ERR_ZERO_SIZE_OBJECT, Http::scServiceUnavailable, request);