jeudi 23 juin 2016

Visual C++, MFC Application, No Malloc, etc at all: What can cause Memory Leak?


Beginner to C++.

I've spent 8+ hours trying to find Google help here.

(added: I installed the trial version of PurifyPlus but my application does not run "inside" it for some reason).

I have an MFC application with a persistent memory leak.

There are a series of threads as: DWORD WINAPI WorkThread( LPVOID lParam ) each of which calls threads as: void TradeLogic( CIBTraderDlg *pDlg ) on a timer.

There is a dialog featuring ListView controls.

There are no "malloc" or "calloc" calls anywhere in the application. (search includes full API) There is a single "new" socket that executes only once when the program starts. There are no dynamic allocations with "new." There is a single read from a file that occurs only once, when the program starts.

But there is a memory leak that persists, ad infinitum. (Roughly 4K bytes every 15 seconds, not exactly uniform though)

My program does not fully run in debug mode. The dialog comes up, but it does not execute any of the calls to a remote server's time thus not the events that key off this (including updating listviews).

Nonetheless, running in "Debug" so qualified, when I click my "Exit" button the Debug output shows the CRT messages as in the documentation but they are not overtly helpful as no leak has occurred at all (they suggest the "new" for the socket can leak but, again, the socket is opened only once). Taskmgr confirms no leak is occurring in this limited mode.

So, I followed the MSDN and tried the following code in the "Exit" sequence:

HANDLE hLogFile;
hLogFile = CreateFile("c:\log.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, hLogFile);

_RPT0(_CRT_ERROR,"file messagen");
_CrtDumpMemoryLeaks();
CloseHandle(hLogFile);
exit(0);

and ran the program normally. But when I click Exit I only get the text "file message" with none of the output of CRT at all to examine.

Can someone point me to where I might look in the code for problems?


Aucun commentaire:

Enregistrer un commentaire