#! /bin/sh /usr/share/dpatch/dpatch-run
## 10_fix-socket-race-condition.dpatch by Adrien Cunin <adri2000@ubuntu.com>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Fix race condition in socket.cpp, upstream rev. 3601, LP: #447224.

@DPATCH@
diff -urNad filezilla-3.3.1~/src/engine/socket.cpp filezilla-3.3.1/src/engine/socket.cpp
--- filezilla-3.3.1~/src/engine/socket.cpp	2010-01-02 15:42:28.000000000 +0100
+++ filezilla-3.3.1/src/engine/socket.cpp	2010-03-11 00:34:29.416328562 +0100
@@ -678,6 +678,17 @@
 			return false;
 		}
 
+		// If state isn't connecting, Close() was called.
+		// If m_pHost is set, Close() was called and Connect()
+		// afterwards, state is back at connecting.
+		// In either case, we need to abort this connection attempt.
+		if (m_pSocket->m_state != CSocket::connecting || m_pHost)
+		{
+			if (!res && addressList)
+				freeaddrinfo(addressList);
+			return false;
+		}
+
 		if (res)
 		{
 #ifdef __WXMSW__