Browse Source

fixed memory leak due to improper termination of MTServerThread.

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@138 595ec19a-5cb4-439b-94a8-42fb3063c22c
ingenuus 21 years ago
parent
commit
bfca3440c4
3 changed files with 11 additions and 3 deletions
  1. 7 0
      CP_Main.cpp
  2. 1 1
      CP_Main.h
  3. 3 2
      Server.cpp

+ 7 - 0
CP_Main.cpp

@@ -180,12 +180,19 @@ void CCP_MainApp::StartStopServerThread()
 	}
 }
 
+void CCP_MainApp::StopServerThread()
+{
+	m_bExitServerThread = true;
+	closesocket(theApp.m_sSocket);
+}
+
 void CCP_MainApp::BeforeMainClose()
 {
 	ASSERT( m_bAppRunning && !m_bAppExiting );
 	m_bAppRunning = false;
 	m_bAppExiting = true;
 	g_HotKeys.UnregisterAll();
+	StopServerThread();
 	StopCopyThread();
 }
 

+ 1 - 1
CP_Main.h

@@ -153,7 +153,7 @@ public:
 	CRITICAL_SECTION m_CriticalSection;
 	CPopup	 *m_pcpSendRecieveError;
 	void	StartStopServerThread();
-
+	void	StopServerThread();
 
 	long	m_lClipsSent;
 	long	m_lClipsRecieved;

+ 3 - 2
Server.cpp

@@ -66,8 +66,9 @@ UINT  MTServerThread(LPVOID pParam)
 			break;
 
 		socket = accept(theApp.m_sSocket, (struct sockaddr*)&from,&fromlen);
-		
-		AfxBeginThread(ClientThread,(LPVOID)socket);
+
+		if( socket != INVALID_SOCKET )
+			AfxBeginThread(ClientThread,(LPVOID)socket);
 	}	
 
 	LogSendRecieveInfo("End of Server Thread");