Finding memory leaks

Don Dilworth 211 Reputation points
2020-10-07T14:11:16.637+00:00

My code runs fine, but when it finishes in debug mode I see many memory leaks. Here are a few:

f:\dd\vctools\crt_bld\self_x86\crt\src\dbgrpt.c(153) : {1208} crt block at 0x273D9DA8, subtype 0, 16 bytes long.
Data: < #a > 00 00 00 00 00 00 00 00 01 00 00 00 B0 23 61 03
f:\dd\vctools\crt_bld\self_x86\crt\src\onexit.c(125) : {791} crt block at 0x273D80C0, subtype 0, 6144 bytes long.
Data: <q$l' %l %l %l > 71 24 6C 27 B6 25 6C BF B6 25 6C BB B0 25 6C A7
f:\dd\vctools\crt_bld\self_x86\crt\src_file.c(129) : {67} crt block at 0x276C1048, subtype 0, 2048 bytes long.
Data: < > 80 DE A4 04 A0 DE A4 04 C0 DE A4 04 E0 DE A4 04
f:\dd\vctools\crt_bld\self_x86\crt\src\stdenvp.c(126) : {65} crt block at 0x276C3540, subtype 0, 1399 bytes long.

How can I find the source of those leaks in my code?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,502 questions
{count} votes

Accepted answer
  1. RLWA32 42,551 Reputation points
    2020-10-07T15:03:51.587+00:00

    My best guess is that the memory leak report is being created before MFC object and other memory allocations have been freed.

    Are you using global and or static objects? Are you creating objects on the heap and forgetting to destroy them?

    Are you using functions that allocate memory and forgetting to free the allocation?

    Without information about the code its difficult to provide specific guidance.

    The path strings reported are not significant. It just indicates that the memory was allocated by MFC.

    If there were inherent problems with MFC then all MFC users would be seeing these memory leaks reported in their debug builds.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. RLWA32 42,551 Reputation points
    2020-10-07T14:34:12.037+00:00
    0 comments No comments

  2. Don Dilworth 211 Reputation points
    2020-10-07T14:50:35.927+00:00

    Excellent suggestion! When I run this, I see some huge memory leaks, but not in my own code:

    Detected memory leaks!
    Dumping objects ->
    {1555} normal block at 0x2740F390, 41 bytes long.
    Data: <h > 68 13 A8 05 18 00 00 00 18 00 00 00 01 00 00 00
    {1543} normal block at 0x2740EFC8, 40 bytes long.
    Data: <h > 68 13 A8 05 01 00 00 00 17 00 00 00 01 00 00 00
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\tooltip.cpp(479) : {1542} normal block at 0x27411B30, 48 bytes long.
    Data: <, U > 2C 00 00 00 00 00 00 00 96 08 15 00 55 80 00 00
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\tooltip.cpp(416) : {1541} client block at 0x27412B68, subtype c0, 144 bytes long.
    a CToolTipCtrl object at $27412B68, 144 bytes long
    {1478} normal block at 0x274349E0, 4080 bytes long.
    Data: < + > 00 2B 00 00 00 00 00 00 00 00 00 00 10 00 00 00
    {1476} normal block at 0x27424738, 66168 bytes long.
    Data: <SSNG @ ^t^> 53 53 4E 47 00 01 00 00 00 00 00 40 8C 5E 74 5E
    {1475} normal block at 0x27400FC8, 23 bytes long.
    Data: <h > 68 13 A8 05 06 00 00 00 06 00 00 00 01 00 00 00
    {1474} normal block at 0x27400D40, 28 bytes long.
    Data: <h > 68 13 A8 05 0B 00 00 00 0B 00 00 00 01 00 00 00

    This is curious, since my drive F: does not have a "dd" folder. It looks like vctools has its own problems. Am I right?

    0 comments No comments

  3. Don Dilworth 211 Reputation points
    2020-10-07T16:59:35.987+00:00

    I suspect the problem is from using an old VS 2010. Is that possible?

    The only other leaks it finds are from my calls to update the Registry:

    WriteProfileInt( "Data_Files", "zoomSliderTop", zoomSlider.top );       // do this last so PAD is closed
    

    I don't see how that could cause a leak -- and anyway, it only occurs on the final exit. Problems that happen while running can't be for that reason. (Corrupted heap)