PRB: Assertion Failed - SOCKCORE.CPP, Line 51Last reviewed: July 18, 1997Article ID: Q130944 |
1.52
WINDOWS
kbprg kberrmsg kbprb kbtshoot
The information in this article applies to:
SYMPTOMSAn 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! CAUSEThis assertion failure most likely occurs if any CSocket or CAsyncSocket objects have not been closed (or destroyed).
RESOLUTIONEnsure 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. STATUSThis behavior is by design.
MORE INFORMATIONFor more information on how to track down memory leaks, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q122307 TITLE : Tracking Down Memory Leaks with _afxBreakAllocUsing the techniques shown in Q122307, you can determine where the socket object was allocated. Sockets require a window to receive notification messages when socket events occur (when data is ready to be received on the socket). MFC manages this notification window for you when you use the MFC socket classes. This window is created by MFC when your application uses a socket object. When all of the socket objects have been closed, MFC destroys the notification window. The assertion failure message is generated by the following line:
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. A common scenario where this might occur is with a server application that opens a listening socket, and the listening socket is left open throughout the execution of the application. In this scenario, you may easily overlook the need to destroy the socket object. For example:
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 reference words: 1.52 2.52
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |