PRB: Assertion Failed - SOCKCORE.CPP, Line 51ID: Q130944
|
An application using MFC's socket classes (CSocket and CAsyncSocket) causes an assertion failure upon exit. The assertion failure text is similar to this:
myapp Windows Application: File sockcore.cpp, Line 51, Assertion Failed!
This assertion failure most likely occurs if any CSocket or CAsyncSocket objects have not been closed (or destroyed).
Ensure that all socket objects in the application are properly closed and
destroyed. If a socket object has been used but was not destroyed, this
message will occur.
Here is a technique you can use to determine which socket object was not
destroyed:
Detected memory leaks! Dumping objects -> {2} a CSocket at $DEF0932 m_hSocket = 0x2 m_pbBlocking = $0 m_nConnectError = -1 Object dump complete.
This behavior is by design.
For more information on how to track down memory leaks, please see the following article in the Microsoft Knowledge Base:
Q122307 Tracking Down Memory Leaks with _afxBreakAllocUsing the techniques shown in Q122307, you can determine where the socket object was allocated.
ASSERT(_afxSockState->hSocketWindow == NULL);
This assertion is verifying that the socket notification window has been
destroyed. Because this window is destroyed when all of the socket objects
have been destroyed, you have most likely created and used a socket object
but never destroyed it.
BOOL CMyApp::InitInstance()
{
// ...
m_pSock = new CListeningSocket;
m_pSock->Create(nPort);
m_pSock->Listen();
// ...
return CWinApp::InitInstance();
}
This is a common sequence of events, but you must remember to destroy the
socket object before exiting the application. For example:
int CMyApp::ExitInstance()
{
delete m_pSock;
return CWinapp::ExitInstance();
}
Additional query words: 1.52 2.52
Keywords : kberrmsg kb16bitonly kbMFC kbVC kbWinsock
Version : 1.52
Platform : WINDOWS
Issue type :
Last Reviewed: August 2, 1999