At my new job I found myself chasing some memory leaks in our rather large C/C++ codebase. Going into the task I was optimistic and just a bit overconfident, knowing as I did that the C Runtime (CRT) has built-in leak-finding goodness.
After the honeymoon, it became clear I was mistaken. Sure, you can set the _CRTDBG_LEAK_CHECK_DF flag with _CrtSetDbgFlag. You can even enable source information with _CRTDBG_MAP_ALLOC. Go ahead. Try it. Use this code:
#include "stdafx.h"
extern "C" int main(INT argc, TCHAR *argv[])
{
char* c = new char[2048];
::strcpy(c, "You're screwed, pal!");
return 0;
}
What? The line number reported for the leak is some bullshit location deep within the CRT? How can this be? The CRT is better than that!
Not.