$OpenBSD: patch-src_BaseClient_cpp,v 1.1 2011/06/24 08:42:31 dcoppa Exp $

Backport a bugfix from upstream git: work around a crash when doubly
deleting a client.

--- src/BaseClient.cpp.orig	Wed Sep  9 22:46:31 2009
+++ src/BaseClient.cpp	Fri Dec  3 10:37:13 2010
@@ -336,6 +336,9 @@ CUpDownClient::~CUpDownClient()
 		delete m_pReqFileAICHHash;
 		m_pReqFileAICHHash = NULL;
 	}
+
+	// Allow detection of deleted clients that didn't go through Safe_Delete
+ 	m_clientState = CS_DYING;
 }
 
 void CUpDownClient::ClearHelloProperties()
@@ -1210,6 +1213,11 @@ void CUpDownClient::ClearDownloadBlockRequests()
 bool CUpDownClient::Disconnected(const wxString& strReason, bool bFromSocket)
 {
 	//wxASSERT(theApp->clientlist->IsValidClient(this));
+
+	if (HasBeenDeleted()) {
+		AddDebugLogLineM( false, logClient, wxT("Disconnected() called for already deleted client on ip ") + Uint32toStringIP(GetConnectIP()));
+		return false;
+	}
 	
 	// was this a direct callback?
 	if (m_dwDirectCallbackTimeout != 0) {
