BC doesn't detect a leak in CSocket/ CAsyncSocket

0 Likes

Problem:

I found a memory leak that I was working with was not detected as a normal memory leak. As long as the application was running memory was being consumed.  Memory was then released when the application was shut down, so technically there was no leak detected by BC's ActiveCheck. But our application is suppose to run for months at a time, but it was crashing after every 3 or 4 days.

Resolution:

It turns out that there is an known undocumented way of using the Csocket and CAsyncSocket classes.  Here is the response from one of the support people at Microsoft:

// Normally we do not respond to bug reports, but I'm familiar with MFC sockets

// and decided to give you some feedback.

//

// Yes, this is a problem, but not a bug in CSockets.  MFC sockets were designed

// to be used in threads with a message pump (although I don't think there's

// documentation that states that!).  Because there is none in your worker

// thread, you are accumulating these MSG objects.  You'll notice at the end of

// CSocket::PumpMessages, a WM_SOCKET_NOTIFY message is posted so that the

// message in the aux queue can be processed, hence, ProcessAuxQueue will be

// processed and the memory object will be deleted.

//

// Another resolution for you might've been to insert a message pump.

//

// If this information does not resolve this issue you are encouraged to

// contact Microsoft Technical Support for Visual C . Please note that you

// will not be charged a service fee for a bug.

You might be able to fix the problem by overriding the PumpMessages function, copying their

implementation, and commenting out the aux queue code.

Old KB# 12243
Comment List
Anonymous
Related Discussions
Recommended