I've really been looking through similar posts, but couldn't really find anything that fits my issue.
I'm trying to make a basic program that makes queries with a MySQL database, and it all works fine, but I have a lot of memory leaks.
#include <cppconn/driver.h>
#include <crtdbg.h>
int main() {
{
sql::Driver* driver = get_driver_instance();
}
_CrtDumpMemoryLeaks();
return 0;
}
This is a small snippet of what I'm using. The rest of it isn't really relevant, since I've observed that even this small bit of code yields a lot of memory leaks, as given by the _CrtDumpMemoryLeaks call.
I got the 64bit version and used the dynamically linked library. What I observed is that I also needed to link the boost library separately, so I downloaded it and put its "include" directory as well.
I'm using Visual Studio 2019 Community.
Any help would be greatly appreciated. Cheers!
This is the output after running the program.
Detected memory leaks!
Dumping objects ->
{193} normal block at 0x0000014FB1F74710, 16 bytes long.
Data: < F O > 90 46 FA B1 4F 01 00 00 00 00 00 00 00 00 00 00
{192} normal block at 0x0000014FB1FA4670, 88 bytes long.
Data: < ( O ( O > 00 28 F6 B1 4F 01 00 00 00 28 F6 B1 4F 01 00 00
{191} normal block at 0x0000014FB1F8CC30, 24 bytes long.
Data: < g > 18 03 67 C5 FE 7F 00 00 01 00 00 00 01 00 00 00
{190} normal block at 0x0000014FB1F8C7B0, 24 bytes long.
Data: < d > A8 96 64 C5 FE 7F 00 00 02 00 00 00 01 00 00 00
{189} normal block at 0x0000014FB1F5E280, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{188} normal block at 0x0000014FB1F57FE0, 168 bytes long.
Data: < > 00 00 00 00 D2 04 00 00 88 00 00 00 00 00 00 00
{187} normal block at 0x0000014FB1F5F5A0, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{186} normal block at 0x0000014FB1F61720, 56 bytes long.
Data: < > 00 00 00 00 D2 04 00 00 18 00 00 00 00 00 00 00
{185} normal block at 0x0000014FB1F71050, 48 bytes long.
Data: < > 00 00 00 00 D2 04 00 00 10 00 00 00 00 00 00 00
{184} normal block at 0x0000014FB1F70DB0, 40 bytes long.
Data: < p O > 00 00 00 00 CD CD CD CD 70 10 F7 B1 4F 01 00 00
{183} normal block at 0x0000014FB1F70D40, 48 bytes long.
Data: < > 00 00 00 00 D2 04 00 00 10 00 00 00 00 00 00 00
{182} normal block at 0x0000014FB1F710C0, 40 bytes long.
Data: < ` O > 00 00 00 00 CD CD CD CD 60 0D F7 B1 4F 01 00 00
{181} normal block at 0x0000014FB1F64C10, 80 bytes long.
Data: <h i dRi > 68 C6 69 C5 FE 7F 00 00 64 52 69 C5 FE 7F 00 00
{180} normal block at 0x0000014FB1F743F0, 16 bytes long.
Data: < L O > 01 00 00 00 00 00 00 00 10 4C F6 B1 4F 01 00 00
{179} normal block at 0x0000014FB1F5BF60, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{178} normal block at 0x0000014FB1F57280, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{177} normal block at 0x0000014FB1F55310, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{176} normal block at 0x0000014FB1F55560, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{175} normal block at 0x0000014FB1F5E560, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{174} normal block at 0x0000014FB1F55EE0, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{173} normal block at 0x0000014FB1F57530, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{172} normal block at 0x0000014FB1F57C50, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{171} normal block at 0x0000014FB1F57960, 104 bytes long.
Data: < > FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00
{170} normal block at 0x0000014FB1F744E0, 8 bytes long.
Data: <8 d > 38 94 64 C5 FE 7F 00 00
{169} normal block at 0x0000014FB1F62560, 24 bytes long.
Data: <0 d D O > 30 8C 64 C5 FE 7F 00 00 E0 44 F7 B1 4F 01 00 00
{168} normal block at 0x0000014FB1F743A0, 16 bytes long.
Data: < f `% O > F0 FE 66 C5 FE 7F 00 00 60 25 F6 B1 4F 01 00 00
{167} normal block at 0x0000014FB1F62800, 88 bytes long.
Data: <pF O pF O > 70 46 FA B1 4F 01 00 00 70 46 FA B1 4F 01 00 00
{166} normal block at 0x0000014FB1F74850, 16 bytes long.
Data: < s > 98 73 E1 C5 FE 7F 00 00 00 00 00 00 00 00 00 00
{162} normal block at 0x0000014FB1F65510, 80 bytes long.
Data: < U O U O > 10 55 F6 B1 4F 01 00 00 10 55 F6 B1 4F 01 00 00
{161} normal block at 0x0000014FB1F74F30, 16 bytes long.
Data: < > D8 D4 E1 C5 FE 7F 00 00 00 00 00 00 00 00 00 00
{160} normal block at 0x0000014FB1F73080, 120 bytes long.
Data: < 0 O 0 O > 80 30 F7 B1 4F 01 00 00 80 30 F7 B1 4F 01 00 00
{159} normal block at 0x0000014FB1F74D00, 16 bytes long.
Data: < > F0 D4 E1 C5 FE 7F 00 00 00 00 00 00 00 00 00 00
{158} normal block at 0x0000014FB1F750C0, 16 bytes long.
Data: <hs > 68 73 E1 C5 FE 7F 00 00 00 00 00 00 00 00 00 00
{157} normal block at 0x0000014FB1F72FE0, 88 bytes long.
Data: < / O / O > E0 2F F7 B1 4F 01 00 00 E0 2F F7 B1 4F 01 00 00
{156} normal block at 0x0000014FB1F74350, 16 bytes long.
Data: < X > 00 58 E1 C5 FE 7F 00 00 00 00 00 00 00 00 00 00
Object dump complete.
So it looks like a lot is leaking, only from calling that single method on the Driver class. The destructor is protected, so I can't call "delete" on it.
This isn't really a memory leak, because you are checking "too early".
Here you can see how get_driver_instance is implemented:
static std::map< sql::SQLString, boost::shared_ptr<MySQL_Driver> > driver;
CPPCONN_PUBLIC_FUNC sql::mysql::MySQL_Driver * get_driver_instance()
{
return get_driver_instance_by_name("");
}
CPPCONN_PUBLIC_FUNC sql::mysql::MySQL_Driver * get_driver_instance_by_name(const char * const clientlib)
{
::sql::SQLString dummy(clientlib);
std::map< sql::SQLString, boost::shared_ptr< MySQL_Driver > >::const_iterator cit;
if ((cit = driver.find(dummy)) != driver.end()) {
return cit->second.get();
} else {
boost::shared_ptr< MySQL_Driver > newDriver;
newDriver.reset(new MySQL_Driver(dummy));
driver[dummy] = newDriver;
return newDriver.get();
}
}
You can see that a global variable driver is created, which is a map of shared_ptrs to the invidiual MySQL_Driver objects. get_driver_instance simply calls get_driver_instance_by_name("") which will return the driver driver[""] or create it if it doesn't exist.
In the shared_ptr documentation you can see that a shared_ptr will delete the pointer that was assigned to it when the shared_ptr itself is destructed. It will be destructed when the map driver is destructed, which will happen when your process is torn down - after main returns.
So, within main, the driver still exists (destructors haven't run yet), so _CrtDumpMemoryLeaks(); will report it as bogus leak.
This is basically the issue described here.
I'm not sure if there is a reliable way to run your code after the destructors though, because the order at which global destructors and atexit handlers run is not specified across different translation units.
Since you are on Windows, one idea would be to (ab)use thread-local storage callbacks, you could run code at the DLL_THREAD_DETACH step which should, as far as I know, run after the regular destructors and such. See this article. (I'm not sure about that though, so I'd be happy if someone could comment who knows this better than I do!)
Related
I am using openssl in my project. When I exit my application I get "Detected memory leaks!" in Visual Studio 2013.
Detected memory leaks!
Dumping objects ->
{70202} normal block at 0x056CB738, 12 bytes long.
Data: <8 j > 38 E8 6A 05 00 00 00 00 04 00 00 00
{70201} normal block at 0x056CB6E8, 16 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{70200} normal block at 0x056CB698, 20 bytes long.
Data: < l > 00 00 00 00 E8 B6 6C 05 00 00 00 00 04 00 00 00
{70199} normal block at 0x056AE838, 12 bytes long.
Data: < l > 04 00 00 00 98 B6 6C 05 00 00 00 00
{70198} normal block at 0x056CB618, 64 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{70197} normal block at 0x056CB578, 96 bytes long.
Data: < l 3 3 > 18 B6 6C 05 00 FE C0 33 C0 FD C0 33 08 00 00 00
Object dump complete.
When I add
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
_CrtSetBreakAlloc(70202);
to main main function I always get a breakpoint at the allocation of the x509 store, no matter for which of the 6 numbers (70202,...) I set the break point.
I initialize and uninitialize the x509 store in a class' constructor and destructor (see below).
Is there anything else I need to look out for when using the x509_STORE?
Foo::CSCACerts::CSCACerts(void)
{
m_store = X509_STORE_new();
}
Foo::CSCACerts::~CSCACerts(void)
{
X509_STORE_free( m_store );
}
because of some (strange) problems in my C++-project I used Visual Leak Detector (for the first time), to check the project on memory leaks.
So I got i.a. the follwoing reports:
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 4 at 0x004D07B0: 200 bytes ----------
Leak Hash: 0xD2D1B4A0, Count: 1, Total 200 bytes
Call Stack (TID 8796):
ucrtbase.dll!malloc()
f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): LASS.exe!operator new() + 0x8 bytes
clr.dll!0x72D616E5()
Data:
28 75 14 03 00 00 00 00 01 00 00 00 00 00 00 00 (u...... ........
9A 99 99 99 99 99 B9 3F 50 00 00 00 0A 00 00 00 .......? P.......
00 00 00 00 F4 01 00 00 00 00 00 00 01 00 00 00 ........ ........
7B 14 AE 47 E1 7A 74 3F 14 00 00 00 BA FF FF FF {..G.zt? ........
00 00 00 00 F4 01 00 00 00 00 00 00 01 00 00 00 ........ ........
7B 14 AE 47 E1 7A 84 3F 00 00 00 00 64 00 00 00 {..G.z.? ....d...
00 00 00 00 01 00 00 00 14 00 00 00 46 00 00 00 ........ ....F...
00 00 00 00 64 00 00 00 00 00 00 00 F4 01 00 00 ....d... ........
01 00 00 00 B8 E2 13 03 F0 AD 18 03 00 00 00 00 ........ ........
C8 E2 13 03 C8 AB 18 03 00 00 00 00 78 E3 13 03 ........ ....x...
B8 AC 18 03 00 00 00 00 68 E2 13 03 E8 AC 18 03 ........ h.......
00 00 00 00 14 00 00 00 01 00 00 00 64 00 00 00 ........ ....d...
01 00 00 00 00 00 00 00 ........ ........
---------- Block 20 at 0x004D0880: 200 bytes ----------
Leak Hash: 0xD2D1B4A0, Count: 1, Total 200 bytes
Call Stack (TID 8796):
ucrtbase.dll!malloc()
f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): LASS.exe!operator new() + 0x8 bytes
clr.dll!0x72D616E5()
Data:
78 74 14 03 00 00 00 00 01 00 00 00 00 00 00 00 xt...... ........
9A 99 99 99 99 99 B9 3F 50 00 00 00 0A 00 00 00 .......? P.......
00 00 00 00 F4 01 00 00 00 00 00 00 01 00 00 00 ........ ........
7B 14 AE 47 E1 7A 74 3F 14 00 00 00 BA FF FF FF {..G.zt? ........
00 00 00 00 F4 01 00 00 00 00 00 00 01 00 00 00 ........ ........
7B 14 AE 47 E1 7A 84 3F 00 00 00 00 64 00 00 00 {..G.z.? ....d...
00 00 00 00 01 00 00 00 14 00 00 00 46 00 00 00 ........ ....F...
00 00 00 00 64 00 00 00 00 00 00 00 F4 01 00 00 ....d... ........
01 00 00 00 38 E2 13 03 00 F0 15 03 00 00 00 00 ....8... ........
B8 E1 13 03 88 00 7F 05 00 00 00 00 08 E2 13 03 ........ ........
20 FF 7E 05 00 00 00 00 E8 E1 13 03 80 FF 7E 05 ..~..... ......~.
00 00 00 00 14 00 00 00 01 00 00 00 64 00 00 00 ........ ....d...
01 00 00 00 00 00 00 00 ........ ........
---------- Block 31 at 0x0053E1B8: 72 bytes ----------
Leak Hash: 0x3F88029B, Count: 1, Total 72 bytes
Call Stack (TID 8796):
ucrtbase.dll!malloc()
f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): LASS.exe!operator new() + 0x8 bytes
clr.dll!0x72D616E5()
Data:
60 BC 55 00 40 3E 80 05 A0 3F 80 05 A0 3F 80 05 `.U.#>.. .?...?..
60 BB 55 00 20 34 18 03 00 00 00 00 00 00 00 00 `.U..4.. ........
00 00 00 00 20 00 00 00 2F 00 00 00 80 BC 55 00 ........ /.....U.
00 2E 18 03 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
20 00 00 00 2F 00 00 00 ..../... ........
---------- Block 33 at 0x0055BB60: 8 bytes ----------
Leak Hash: 0xA49C5AA6, Count: 1, Total 8 bytes
Call Stack (TID 8796):
ucrtbase.dll!malloc()
f:\dd\vctools\crt\vcstartup\src\heap\new_scalar.cpp (19): LASS.exe!operator new() + 0x8 bytes
clr.dll!0x72D616E5()
Data:
C8 E1 53 00 00 00 00 00
..S..... ........
//And many more...
Unfortunatly I do not understand, what VLD wants to say is the problem.
With a double-click on the "f:\dd..."-lines it should set my courser to the line with the problem, shouldn´t it? But it dosen´t.
My question is now: How do I get to the area of the problem or in other words "how do I read these reports"?
In addition:
I use Visual Studio 2015
The project is a C++ Windows Forms Project
I included the vld.h in the additional includes and the lib-directory to the additional libraries of the project
In the main() I use #include <vld.h> and _CrtDumpMemoryLeaks();
EDIT:
My Main (a reduced version, but gives similar reports):
//some class-includes
#include <vld.h>
using namespace System;
using namespace System::Windows::Forms;
using namespace std;
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
[STAThread]
void Main()
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Experiment* experiment = new Experiment();
Experiment_List* running_experiments = new Experiment_List();
while(!experiment->end) {
experiment= new Experiment();
LASS::MainWindow form(experiment, running_experiments);
form.ShowDialog();
if(!experiment->end){
running_experiments->register_experiment(experiment);
}
}
running_experimente->end_all();
_CrtDumpMemoryLeaks();
exit(0);
}
Unfortunatley there are about 40 classes, that I do not want to post...
I don't know where the problem exact is.
For me, it helps to run the program in RELEASE Mode, instead of DEBUG mode.
I suppose, my problem is the handling of managed and unmanaged code together.
I have unmanaged code inside managed code.
It seams as if CLR use a different new operator in Debug mode. Not as conform as the c++ standard.
According to: Using push_back() for STL List in C++ causes Access Violation, Crash
If you malloc() a C++ class, no constructors will be called for any of
that class's fields
And the VS will step into a constructor in class new_scalar.cpp.
Folks say that is depending of the Visual Leak Detector (VLD). You use them in your includes.
In the End, try to distinguish your code with
#pragma managed
and
#pragma unmanaged
And run in RELEASE mode.
I have client/server app. Interaction implemented via Boost.Asio.
I created unit test to check long running transmission of data.
During the test memory leak detected.
Task Manager shows me that memory usage constantly grows - up to 35MB per 10min. Report produced at the end of test contains this:
Result StandardError: Detected memory leaks!
Dumping objects ->
{14522} normal block at 0x00E8ADC0, 16 bytes long.
Data: < _M} Y > B0 5F 4D 7D F9 59 F2 02 F4 E9 E6 00 CC CC CC CC
{14012} normal block at 0x00E8B280, 16 bytes long.
Data: < v > C0 76 A4 00 94 01 00 00 98 01 00 00 F0 D2 E3 00
{14011} normal block at 0x00E74B38, 12 bytes long.
Data: < > 00 00 00 00 9C 01 00 00 98 01 00 00
{14007} normal block at 0x00E745F8, 8 bytes long.
Data: < L > E0 4C E5 00 00 00 00 00
{14006} normal block at 0x00E54CB8, 60 bytes long.
Data: < v 4 > E4 76 A4 00 D0 D3 B0 00 00 00 00 00 34 80 E3 00
{13724} normal block at 0x00E710F8, 385 bytes long.
Data: < > 03 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{13722} normal block at 0x00E85C58, 28 bytes long.
Data: < F _ _ > F2 B6 46 00 B4 5F E3 00 A0 5F E3 00 BC 96 E7 00
{13720} normal block at 0x00E6F9B8, 80 bytes long.
Data: <wxF > 77 78 46 00 FC FF FF FF 00 00 00 00 CC CC CC CC
{13700} normal block at 0x00E6DFD0, 88 bytes long.
Data: < > C8 A4 A4 00 01 00 00 00 01 00 00 00 00 00 00 00
…
Data: <` X L > 60 8E E0 00 58 17 E2 00 CD 4C F7 EA
{153} normal block at 0x00DF0070, 12 bytes long.
Data: <` kf > 60 8D E0 00 98 00 E2 00 15 6B 66 0E
{151} normal block at 0x00DF0038, 12 bytes long.
Data: < .g> 20 86 E0 00 E0 FC E1 00 9D B7 2E 67
{149} normal block at 0x00DF0658, 12 bytes long.
Data: < G > A0 89 E0 00 00 00 00 00 47 01 D5 11
{147} normal block at 0x00DF0268, 12 bytes long.
Data: <` > 60 84 E0 00 A8 F5 E1 00 ED 8C AA BA
{145} normal block at 0x00DF0230, 12 bytes long.
Data: < ' " > 20 84 E0 00 00 11 E2 00 27 B0 22 00
{143} normal block at 0x00DF0690, 12 bytes long.
Data: <` P KnOQ> 60 88 E0 00 50 04 E2 00 4B 6E 4F 51
{141} normal block at 0x00DF0540, 12 bytes long.
Data: <` > 7> 60 82 E0 00 00 0A E2 00 3E 0D 9E 37
{139} normal block at 0x00DF0620, 12 bytes long.
Data: <Pq 1 > 50 71 DF 00 00 00 00 00 E5 DD 31 B5
{137} normal block at 0x00DF0700, 12 bytes long.
Data: < q # #> 10 71 DF 00 40 FA E1 00 14 8B 0D 23
{134} normal block at 0x00DF5CE0, 96 bytes long.
Data: <h BV BV > 68 19 E0 00 D0 42 56 00 E0 42 56 00 88 00 00 00
{133} normal block at 0x00DF0188, 8 bytes long.
Data: < \ > A0 5C DF 00 00 00 00 00
{132} normal block at 0x00DF5CA0, 16 bytes long.
Data: < > 88 01 DF 00 D8 AA DF 00 20 AC DF 00 20 AC DF 00
Object dump complete.
I tried to put breakpoint to mentioned memory allocations via boost's --detect_memory_leaks="allocation number" and setting in Watch window at Debug mode _crtBreakAlloc = 1000. It does not work. Maybe because leaks occur not in my code, but in boost/OpenSSL code?
I can't figure out where leaks occur. What can I do?
Windows 8, Visual Studio 2015, boost 1.60, OpenSSL 1.0.2g
Have a look at this post to see some suggested tips for dealing with memory leaks under windows. Have a scroll down, don't just look at the first answer. In particular it may be worth considering the DEBUG_NEW macro-based solution discussed by the second answer. Given that boost asio is largely header-only, this should help you even if the offending allocations come from the boost library.
Part 1: Report from Visual Studio about memory leaks
I'm using Boost.Asio to communicate with the server over TLS, i.e. Boost.Asio uses OpenSSL.
Seems that OpenSSL initializes itself and do not cleans memory before the end of the app (because app closes and memory will be released anyway).
This is not big chunk of memory (I do not know how to measure it).
As result Visual Studio treated that memory as leak. But it is not.
(This is my assumption, maybe real reason for such report is smth else. But I do not see any other possible reasons. )
Part 2:
In the question above I asked about memory leak for tens of Mb. This is my bad code that leads to huge memory buffer )).
Huge memory consumption and report from VisualStudio about memory leak made me believe that smth is very wrong ))
Buffer easily reduced to much smaller size.
I got memory dump by using #define _CRTDBG_MAP_ALLOC in output window.
Detected memory leaks!
Dumping objects ->
{1078301} normal block at 0x0AB2D840, 48 bytes long.
Data: <2 0 1 4 - 0 9 - > 32 00 30 00 31 00 34 00 2D 00 30 00 39 00 2D 00
{975444} normal block at 0x08D21138, 36 bytes long.
Data: < = = pa > A4 3D C0 08 B0 3D C0 08 01 00 00 00 70 61 BE 08
{975443} normal block at 0x0CE96610, 32 bytes long.
Data: <,X \ pa > 2C 58 C0 08 5C 90 BF 08 01 00 00 00 70 61 BE 08
{975438} normal block at 0x0CE6B1D8, 32 bytes long.
Data: 50 90 BF 08 5C 90 BF 08 01 00 00 00 08 E3 D1 08
{736753} normal block at 0x0CEAA878, 16384 bytes long.
Data: < / / > D8 2F D2 08 D8 2F D2 08 03 00 00 00 00 00 00 00
{736744} normal block at 0x0CEA8838, 8192 bytes long.
Data: <8 8 > 38 0B E2 0C 38 88 EA 0C 01 00 00 00 01 00 00 00
{736738} normal block at 0x0CEA47F8, 16384 bytes long.
Data: < G > 00 00 00 00 F8 47 EA 0C 03 00 00 00 00 00 00 00
{736729} normal block at 0x0CE105A8, 8192 bytes long.
Data: <( > 28 14 D1 08 A8 05 E1 0C 01 00 00 00 CD CD CD CD
{736723} normal block at 0x0CEA07B8, 16384 bytes long.
Data: < G 8 > F8 47 EA 0C 38 88 EA 0C 03 00 00 00 00 00 00 00
{736713} normal block at 0x0CE1E440, 8192 bytes long.
Data: < # > A8 05 E1 0C 40 E4 E1 0C 01 00 00 00 CD CD CD CD
{736707} normal block at 0x0CE1A400, 16384 bytes long.
Data: < > B8 07 EA 0C B8 07 EA 0C 03 00 00 00 00 00 00 00
{736698} normal block at 0x0CE36B18, 8192 bytes long.
Data: <# k > 40 E4 E1 0C 18 6B E3 0C 01 00 00 00 CD CD CD CD
{736692} normal block at 0x0CE163C0, 16384 bytes long.
Data: < > 00 A4 E1 0C 00 A4 E1 0C 03 00 00 00 00 00 00 00
{736682} normal block at 0x0CE44230, 8192 bytes long.
Data: < k 0B > 18 6B E3 0C 30 42 E4 0C 01 00 00 00 CD CD CD CD
{736676} normal block at 0x0CE3E7F8, 16384 bytes long.
Data: < c c > C0 63 E1 0C C0 63 E1 0C 03 00 00 00 00 00 00 00
{736666} normal block at 0x0CE4B6F0, 8192 bytes long.
Data: <0B > 30 42 E4 0C F0 B6 E4 0C 01 00 00 00 CD CD CD CD
{736660} normal block at 0x0CE3A7B8, 16384 bytes long.
Data: < > F8 E7 E3 0C F8 E7 E3 0C 03 00 00 00 00 00 00 00
{736650} normal block at 0x0CE47388, 8192 bytes long.
Data: < s > F0 B6 E4 0C 88 73 E4 0C 01 00 00 00 CD CD CD CD
{736644} normal block at 0x0CE0C568, 16384 bytes long.
Data: < > B8 A7 E3 0C B8 A7 E3 0C 03 00 00 00 00 00 00 00
{736634} normal block at 0x0CE20B38, 8192 bytes long.
Data: < s 8 > 88 73 E4 0C 38 0B E2 0C 01 00 00 00 CD CD CD CD
{736628} normal block at 0x0CE23B70, 16384 bytes long.
Data: 68 C5 E0 0C 68 C5 E0 0C 03 00 00 00 00 00 00 00
{663741} normal block at 0x0CDB6EF0, 60 bytes long.
Data: 50 F2 BF 08 24 6F C0 08 01 00 00 00 30 75 00 00
{1923} normal block at 0x08D20DE8, 8 bytes long.
Data: <#] d > 40 5D BE 08 64 C0 D1 08
{1922} normal block at 0x08D22E10, 56 bytes long.
Data: 70 5C BE 08 00 00 00 00 CD CD CD CD E8 0D D2 08
{1900} normal block at 0x08D27018, 16384 bytes long.
Data: < > F0 E2 D1 08 F0 E2 D1 08 03 00 00 00 00 00 00 00
{1894} normal block at 0x08D22FD8, 16384 bytes long.
Data: 70 3B E2 0C 70 3B E2 0C 03 00 00 00 00 00 00 00
{1883} normal block at 0x08D22900, 144 bytes long.
Data: 43 00 3A 00 5C 00 55 00 73 00 65 00 72 00 73 00
Object dump complete.
Now debegger hits the breakpoint. In watch window, at the time of debuging I add {,,msvcr100d.dll}_crtBreakAlloc in name columm and I add memory location 736723 which is the memory block number in the dump mentioned above in the value columm. This leak happens in a function that loops.
When I continue debugging, it breaks at the memory block number that is entered in watch window see fig 1
press break in the window
see fig 2
_CrtDbgBreak holds 0x69595280.thats where memory leak happens
Now, how do I get to know the pointer that holds particular address loaction at the time of debugging.
Thanks in Advance
Avinash V
The program already breaks there, so you should go the call stack window in Visual studio and find the source code there, then you can find the source code which calls the memory allocation function, that is what you're looking for.
As you're using the allocation number to tracking memory leaks, the allocation number can change if the program doesn't run under previous conditions. Please refer: Finding Memory Leaks Using the CRT Library
I am testing my dll that I created. It in turn use several other dlls. My Dll tester application reports memory leaks when I start the test application and exit without doing anything except loading dll using LoadLibrary. It doesn't show the exact files in my dll source code. There are no leaks if I don't load the dll. It is an MFC dll and has App class. I removed everything from the dll's app class so it does nothing but I still get memory leaks report when I load it. I created another set of dummy dll and test application but that doesn't report any leaks so it has to do with my original dll, perhaps its linkage with other dlls?
I have tried using _crtBreakAlloc = {allocation_#}; technique but it doesn't stop the debugger either. I am quite lost if this memory leak is real. I see from documentation it can report false positive. Could this be false positive just because my dll is linked to bunch of other dlls? I can't think of anything else because I have commented out all functionality from dll.
Here is the memory leak erros
Detected memory leaks!
Dumping objects ->
{250} client block at 0x00567E40, subtype c0, 64 bytes long.
a CDynLinkLibrary object at $00567E40, 64 bytes long
a CDynLinkLibrary object at $00567E40, 64 bytes long
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {244} normal block at 0x00567C20, 28 bytes long.
Data: < x > E4 B8 07 78 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {243} normal block at 0x00567BC8, 28 bytes long.
Data: < x > E4 B8 07 78 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {242} normal block at 0x00567B58, 52 bytes long.
Data: < x > E4 B8 07 78 11 00 00 00 11 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {241} normal block at 0x00566C08, 40 bytes long.
Data: < x > E4 B8 07 78 0B 00 00 00 0B 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {240} normal block at 0x00566BA8, 32 bytes long.
Data: < x > E4 B8 07 78 07 00 00 00 07 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {239} normal block at 0x00566B50, 28 bytes long.
Data: < x > E4 B8 07 78 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {238} normal block at 0x00566AE0, 46 bytes long.
Data: < x > E4 B8 07 78 0E 00 00 00 0E 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {237} normal block at 0x00566A70, 48 bytes long.
Data: < x > E4 B8 07 78 0F 00 00 00 0F 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {235} normal block at 0x005676B0, 42 bytes long.
Data: < x > E4 B8 07 78 0C 00 00 00 0C 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {234} normal block at 0x00567658, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {233} normal block at 0x00567600, 28 bytes long.
Data: < x > E4 B8 07 78 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {232} normal block at 0x00567590, 50 bytes long.
Data: < x > E4 B8 07 78 10 00 00 00 10 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {231} normal block at 0x00567538, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {230} normal block at 0x005674E0, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {229} normal block at 0x00567488, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {228} normal block at 0x00567430, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {227} normal block at 0x005673D8, 24 bytes long.
Data: < x > E4 B8 07 78 03 00 00 00 03 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {226} normal block at 0x00567380, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {225} normal block at 0x00567328, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {224} normal block at 0x005672C0, 40 bytes long.
Data: < x > E4 B8 07 78 0B 00 00 00 0B 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {223} normal block at 0x00567268, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {222} normal block at 0x00567200, 44 bytes long.
Data: < x > E4 B8 07 78 0D 00 00 00 0D 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {221} normal block at 0x00567198, 38 bytes long.
Data: < x > E4 B8 07 78 0A 00 00 00 0A 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {220} normal block at 0x00567140, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {219} normal block at 0x005670E8, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {218} normal block at 0x00567080, 38 bytes long.
Data: < x > E4 B8 07 78 0A 00 00 00 0A 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {217} normal block at 0x00567028, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {216} normal block at 0x00566FD0, 24 bytes long.
Data: < x > E4 B8 07 78 03 00 00 00 03 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {215} normal block at 0x00566F78, 24 bytes long.
Data: < x > E4 B8 07 78 03 00 00 00 03 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {214} normal block at 0x00566F18, 36 bytes long.
Data: < x > E4 B8 07 78 09 00 00 00 09 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {213} normal block at 0x00566EC0, 24 bytes long.
Data: < x > E4 B8 07 78 03 00 00 00 03 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {212} normal block at 0x00566E68, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {211} normal block at 0x00566E10, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {210} normal block at 0x00566DB8, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {209} normal block at 0x00566D60, 24 bytes long.
Data: < x > E4 B8 07 78 03 00 00 00 03 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {208} normal block at 0x00566D08, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {207} normal block at 0x00566CB0, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {206} normal block at 0x00561918, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {205} normal block at 0x005618C0, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {204} normal block at 0x00561868, 28 bytes long.
Data: < x > E4 B8 07 78 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {202} normal block at 0x005669F8, 60 bytes long.
Data: < x > E4 B8 07 78 15 00 00 00 15 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {201} normal block at 0x00566988, 46 bytes long.
Data: < x > E4 B8 07 78 0E 00 00 00 0E 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {200} normal block at 0x00566920, 42 bytes long.
Data: < x > E4 B8 07 78 0C 00 00 00 0C 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {199} normal block at 0x005668C8, 28 bytes long.
Data: < x > E4 B8 07 78 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {198} normal block at 0x00566868, 32 bytes long.
Data: < x > E4 B8 07 78 07 00 00 00 07 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {197} normal block at 0x00566800, 44 bytes long.
Data: < x > E4 B8 07 78 0D 00 00 00 0D 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {196} normal block at 0x00566790, 50 bytes long.
Data: < x > E4 B8 07 78 10 00 00 00 10 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {195} normal block at 0x00566718, 60 bytes long.
Data: < x > E4 B8 07 78 15 00 00 00 15 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {194} normal block at 0x005666C0, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {193} normal block at 0x00566040, 48 bytes long.
Data: < x > E4 B8 07 78 0F 00 00 00 0F 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {192} normal block at 0x00561C98, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {81} normal block at 0x00561BA0, 32 bytes long.
Data: < x > E4 B8 07 78 07 00 00 00 07 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {80} normal block at 0x00561B48, 28 bytes long.
Data: < x > E4 B8 07 78 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {79} normal block at 0x00561AE0, 44 bytes long.
Data: < x > E4 B8 07 78 0D 00 00 00 0D 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {78} normal block at 0x00561A80, 34 bytes long.
Data: < x > E4 B8 07 78 08 00 00 00 08 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {77} normal block at 0x00561A20, 30 bytes long.
Data: < x > E4 B8 07 78 06 00 00 00 06 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {76} normal block at 0x005613D0, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {75} normal block at 0x005619A8, 56 bytes long.
Data: < x > E4 B8 07 78 13 00 00 00 13 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {74} normal block at 0x00561378, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {72} normal block at 0x005617F8, 48 bytes long.
Data: < x > E4 B8 07 78 0F 00 00 00 0F 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {71} normal block at 0x005617A0, 28 bytes long.
Data: < x > E4 B8 07 78 05 00 00 00 05 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {70} normal block at 0x00561748, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {69} normal block at 0x005616D0, 54 bytes long.
Data: < x > E4 B8 07 78 12 00 00 00 12 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {68} normal block at 0x00561670, 34 bytes long.
Data: < x > E4 B8 07 78 08 00 00 00 08 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {67} normal block at 0x00561618, 22 bytes long.
Data: < x > E4 B8 07 78 02 00 00 00 02 00 00 00 01 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(156) : {66} normal block at 0x005615B8, 36 bytes long.
Data: < x > E4 B8 07 78 09 00 00 00 09 00 00 00 01 00 00 00
Object dump complete.
Is there another way I can double check the memory leaks don't exist? I installed deleaker as well but it is buggy program, it holds on pdb files and was not releasing it...that caused me more pain.
According to the following MSKB article, this is probably expected:
Memory leaks are reported when you use multiple MFC DLLs
Quoting from the linked page:
These memory leaks are reported when multiple versions of the MFC DLL
are loaded in the same process. Since MFC extension (AFXDLL) DLLs
require the exact same MFC DLL as the call application, this problem
can only occur when using MFC regular (USRDLL) DLLs or ActiveX
Controls (OCX) that use the shared version of MFC.
The most common case is mixing ANSI (MFC4xd.DLL) and UNICODE
(MFC4xxUd.DLL) versions of MFC in the same process. This can also
occur when mixing MFC42d.DLL and MFC40d.DLL.
And as far as resolving the "problem" goes:
These memory leak notifications are false, and can be ignored. Since
neither copy of MFC knows about the other ones, it's not easy to stop
these false leaks from being reported.