From 583ff2b16f409e1b8bf287e6aa234b6736b90380 Mon Sep 17 00:00:00 2001
From: Burlen Loring <bloring@lbl.gov>
Date: Mon, 2 May 2011 15:36:32 -0700
Subject: [PATCH] BUG: PV bug 0012130, double close by classes derived from vtkSocket.

---
 Common/vtkSocket.cxx |    7 +++----
 Common/vtkSocket.h   |    4 ++--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/Common/vtkSocket.cxx b/Common/vtkSocket.cxx
index 43290fa..4b7589b 100644
--- a/Common/vtkSocket.cxx
+++ b/Common/vtkSocket.cxx
@@ -130,7 +130,6 @@ vtkSocket::~vtkSocket()
   if (this->SocketDescriptor != -1)
     {
     this->CloseSocket(this->SocketDescriptor);
-    this->SocketDescriptor = -1;
     }
 }
 
@@ -168,7 +167,6 @@ int vtkSocket::CreateSocket()
 void vtkSocket::CloseSocket()
 {
   this->CloseSocket(this->SocketDescriptor);
-  this->SocketDescriptor = -1;
 }
 
 //-----------------------------------------------------------------------------
@@ -521,7 +519,7 @@ int vtkSocket::GetPort(int sock)
 }
 
 //-----------------------------------------------------------------------------
-void vtkSocket::CloseSocket(int socketdescriptor)
+void vtkSocket::CloseSocket(int &socketdescriptor)
 {
 #ifndef VTK_SOCKET_FAKE_API
   if (socketdescriptor < 0)
@@ -538,8 +536,9 @@ void vtkSocket::CloseSocket(int socketdescriptor)
     vtkSocketErrorMacro(
       vtkErrnoMacro, "Socket error in call to close/closesocket.");
     }
+  socketdescriptor = -1;
 #else
-  static_cast<void>(socketdescriptor);
+  socketdescriptor = -1;
   return;
 #endif
 }
diff --git a/Common/vtkSocket.h b/Common/vtkSocket.h
index c93e16a..0a945df 100644
--- a/Common/vtkSocket.h
+++ b/Common/vtkSocket.h
@@ -80,8 +80,8 @@ protected:
   int CreateSocket();
 
   // Description:
-  // Close the socket.
-  void CloseSocket(int socketdescriptor);
+  // Close the socket, and marks the descriptor invalid.
+  void CloseSocket(int &socketdescriptor);
 
   // Description:
   // Binds socket to a particular port.
-- 
1.7.0.4

