perl/win32/runperl.c
Steve Hay 924c839e69 Turn on memory leak reporting for CFG = DebugFull builds on Windows
Setting _CRTDBG_LEAK_CHECK_DF arranges for _CrtDumpMemoryLeaks() to be
called automatically at program termination, outputting a report of all
allocations that have not been freed into the Output window in Developer
Studio.

If a leak is reported then note its allocation number, change the -1 in
the _CrtSetBreakAlloc(-1L) call to the leaked allocation number and
rebuild. A breakpoint will be set on the allocation call that leaked.

(A slicker approach is to have the report include the file name and line
number of the leaked allocation call by inserting

#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>

early in each compilation unit (e.g. by inserting it early in perl.h), but
that works by re-#defining malloc/free etc, which unfortunately clashes
with #defines in win32/win32iop.h and with the 'free' member of the
regexp_engine struct in regexp.h.)
2015-02-15 16:06:43 +00:00

43 lines
1.1 KiB
C

#ifdef _MSC_VER
#include <crtdbg.h>
#endif
#include "EXTERN.h"
#include "perl.h"
#ifdef __GNUC__
/* Mingw32 defaults to globing command line
* This is inconsistent with other Win32 ports and
* seems to cause trouble with passing -DXSVERSION=\"1.6\"
* So we turn it off like this, but only when compiling
* perlmain.c: perlmainst.c is linked into the same executable
* as win32.c, which also does this, so we mustn't do it twice
* otherwise we get a multiple definition error.
*/
#ifndef PERLDLL
int _CRT_glob = 0;
#endif
#endif
int
main(int argc, char **argv, char **env)
{
#ifdef _MSC_VER
/* Arrange for _CrtDumpMemoryLeaks() to be called automatically at program
* termination when built with CFG = DebugFull. */
int currentFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
currentFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(currentFlag);
/* Change this -1 to the allocation number of any reported memory leaks to
* break on the allocation call that was leaked. */
_CrtSetBreakAlloc(-1L);
#endif
return RunPerl(argc, argv, env);
}