0

I was investigating a memory leak with the application written in C# & C++. Once I have isolated it to couple of C++ components with PerfMon log and WinDbg/SOS debugging I tried to use UMDH (gflags enabled with +ust) to compare snapshots and find out which heap allocations were leaking memory.

At end the leak was found by a manual review of code. The sample code snippet below.

char *p = new char[size];
// use the pointer 
delete p;  <---- MEMORY LEAK

I was wondering why UMDH didn't catch this ? UMDH never reported this as an issue in the comparison log. Would WinDbg heap commmands would have helped to point out the leak ?

trincot
  • 317,000
  • 35
  • 244
  • 286
Prasad
  • 1
  • 1
  • 1
    Believe it or not, your code as written tends not to leak on msvc. The difference in msvc between the `scalar deleter` and the `vector deleter` is that the `vector deleter` will call destructors of the individual elements in the array. Since `char` is trivial, there is no leak. (It's still a malformed program and bad, but it tends to work.) [screenshot showing no growth](http://i.imgur.com/fSgmu5v.png) – Sean Cline Jan 27 '16 at 03:52
  • That's a very strange observation and hard to believe until a ran a sample code. Even though we just use a "delete p" not sure how the memory is being freed for the entire character array. – Prasad Jan 27 '16 at 18:12

0 Answers0