Просмотр исходного кода

Fix: incorrect use of defer caused byteUp/Down to be evaluated when 0

Rod Hynes 9 лет назад
Родитель
Сommit
2a02375fb0
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      psiphon/server/tunnelServer.go

+ 6 - 2
psiphon/server/tunnelServer.go

@@ -635,8 +635,12 @@ func (sshClient *sshClient) handleTCPChannel(
 
 	var bytesUp, bytesDown int64
 	sshClient.openedPortForward(sshClient.tcpTrafficState)
-	defer sshClient.closedPortForward(
-		sshClient.tcpTrafficState, atomic.LoadInt64(&bytesUp), atomic.LoadInt64(&bytesDown))
+	defer func() {
+		sshClient.closedPortForward(
+			sshClient.tcpTrafficState,
+			atomic.LoadInt64(&bytesUp),
+			atomic.LoadInt64(&bytesDown))
+	}()
 
 	// TOCTOU note: important to increment the port forward count (via
 	// openPortForward) _before_ checking isPortForwardLimitExceeded