I have the following C code:
// cl /Zi /Fe.buildmain.exe /Fo.buildmain.o .srcmain.c
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Hello World!n");
int *ptr = malloc(sizeof(int));
*ptr = 7;
printf("address of ptr: %p, value of ptr: %dn", ptr, *ptr);
_CrtDumpMemoryLeaks();
return 0;
}
I attempted to make a deliberate memory leak in the above code so I can test the memory leak detection. However I’m not getting any reports at the end of executing the resulting exe
file. Any ideas?
I’m following the guide from Microsoft that can be found here:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/find-memory-leaks-using-the-crt-library?view=msvc-170&viewFallbackFrom=vs-2019#interpret-the-memory-leak-report
I’m using the following command to build the above source file:
cl /Zi /Fe.buildmain.exe /Fo.buildmain.o .srcmain.c && .buildmain.exe