Ejemplo n.º 1
0
void installMemLeakDetector()
{
#if defined _MSC_VER && defined USE_LEAKDETECTOR
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetAllocHook(crtDebugMemAllocHook);
#endif
}
Ejemplo n.º 2
0
void debugInstallFreeHook(void)
{
#if defined(_WIN32) && defined(_DEBUG)
    lastCrtAllocHook = _CrtSetAllocHook(DebugAllocHook);
#endif

#ifdef __GLIBC__
    // __free_hook is not thread safe so it marked as deprecated.  Use here
    // is hopefully safe and should catch errors in a single threaded program
    // and only miss some in a multithreaded program
    lastFreeHook = __free_hook;
    __free_hook = DebugFreeHook;
#endif

#ifdef __APPLE__
    malloc_zone_t* zone = malloc_default_zone();
    assert(zone != NULL);
    //remove the write protection from the zone struct
    if (zone->version >= 8) {
      vm_protect(mach_task_self(), (uintptr_t)zone, sizeof(*zone), 0, VM_PROT_READ | VM_PROT_WRITE);
    }
    lastMallocZone = *zone;
    zone->free = DebugFreeHook;
    zone->free_definite_size = DebugFreeDefiniteSizeHook;
    if (zone->version >= 8) {
      vm_protect(mach_task_self(), (uintptr_t)zone, sizeof(*zone), 0, VM_PROT_READ);
    }
#endif
}
Ejemplo n.º 3
0
/*----------------------------------------------------------------------
|       main
+---------------------------------------------------------------------*/
int
main(int argc, char** argv) 
{
    NPT_COMPILER_UNUSED(argc);
    NPT_COMPILER_UNUSED(argv);

#if defined(WIN32) && defined(_DEBUG)
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF    |
                   _CRTDBG_CHECK_ALWAYS_DF |
                   _CRTDBG_LEAK_CHECK_DF);
    _CrtSetAllocHook(AllocHook);
#endif
    
    TestSharedVariables();
    TestPrio();
    Test3(100000, 0.0f, 0.0f);
    Test3(300, 0.1f, 0.0f);
    Test3(100, 0.5f, 0.4f);
    Test4();
    Test1();
    Test2();

    NPT_Debug("- program done -\n");

    return 0;
}
Ejemplo n.º 4
0
void EnableCRTAllocHook(BOOL fEnable)
{
#ifdef _DEBUG
	if(fEnable)
	{
		if(!g_fpPrevCRTAllocHook)
			g_fpPrevCRTAllocHook	= (_CRT_ALLOC_HOOK_SIGNED)_CrtSetAllocHook((_CRT_ALLOC_HOOK)&CRTAllocHook);
	}
	else
	{
		if(g_fpPrevCRTAllocHook)
			_CrtSetAllocHook((_CRT_ALLOC_HOOK)g_fpPrevCRTAllocHook);
		g_fpPrevCRTAllocHook = NULL;
	}
#endif //_DEBUG
}
Ejemplo n.º 5
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	_CrtSetAllocHook(CrtAllocHook);
	xo::RunApp(xoMain);
	_CrtDumpMemoryLeaks();
	return 0;
}
Ejemplo n.º 6
0
AFX_ALLOC_HOOK AFXAPI AfxSetAllocHook(AFX_ALLOC_HOOK pfnNewHook)
{
	if (pfnCrtAllocHook == NULL)
		pfnCrtAllocHook = _CrtSetAllocHook(_AfxAllocHookProxy);

	AFX_ALLOC_HOOK pfnOldHook = pfnAllocHook;
	pfnAllocHook = pfnNewHook;
	return pfnOldHook;
}
Ejemplo n.º 7
0
void CMemLeakDetect::Init()
{
      AllocBlockInfo::initSymbols();
      m_AllocatedMemoryList.InitHashTable(10211, TRUE);
      isLocked              = false;
      g_pMemTrace           = this;
      pfnOldCrtAllocHook    = _CrtSetAllocHook( catchMemoryAllocHook ); 
      _crtDbgFlag = _crtDbgFlag | _CRTDBG_ALLOC_MEM_DF;
}
Ejemplo n.º 8
0
_MRTIMP _CRT_ALLOC_HOOK __cdecl _CrtSetAllocHook
(
    int pfnNewHook
)
{
    _VALIDATE_RETURN(pfnNewHook == 0, EINVAL, NULL);

    return _CrtSetAllocHook((_CRT_ALLOC_HOOK)NULL);
}
Ejemplo n.º 9
0
void CMemLeakDetect::End()
{
    isLocked                = true;
    _CrtSetAllocHook(pfnOldCrtAllocHook);
    dumpMemoryTrace();
    cleanupMemoryTrace();
    g_pMemTrace             = NULL;
    AllocBlockInfo::deinitSymbols();
}
Ejemplo n.º 10
0
static void __clrcall _CrtAllocHook_managed_cleanup(void)
{
    _CRT_ALLOC_HOOK pfnAllocHook=_CrtGetAllocHook();
    _CRT_ALLOC_HOOK_M enull = (_CRT_ALLOC_HOOK_M) EncodePointer(NULL)();
    if(pfnAllocHook==_CrtAllocHook_managed_thunk && __pfnAllocHookManaged!=enull)
    {
        _CrtSetAllocHook((_CRT_ALLOC_HOOK)NULL);
    }
    __pfnAllocHookManaged=enull;
}
Ejemplo n.º 11
0
void CMemLeakDetect::End()
{
	isLocked				= true;
	_CrtSetAllocHook(pfnOldCrtAllocHook);
	dumpMemoryTrace();
	cleanupMemoryTrace();
	cleanupSymInfo();
	GlobalFree(m_pSymbol);
	g_pMemTrace				= NULL;
	FreeLibrary(m_k32);
}
Ejemplo n.º 12
0
void CMemLeakDetect::Init()
{
	m_func = (CaptureStackBackTraceType)(GetProcAddress( m_k32 = LoadLibrary(_T("kernel32.dll")), "RtlCaptureStackBackTrace"));
	m_dwsymBufSize		= (MLD_MAX_NAME_LENGTH + sizeof(PIMAGEHLP_SYMBOL));
	m_hProcess			= GetCurrentProcess();
	m_pSymbol				= (IMAGE_SYM)GlobalAlloc( GMEM_FIXED, m_dwsymBufSize);
	m_AllocatedMemoryList.InitHashTable(10211, TRUE);
	initSymInfo( NULL );
	isLocked				= false;
	g_pMemTrace			= this;
	pfnOldCrtAllocHook	= _CrtSetAllocHook( catchMemoryAllocHook ); 
}
Ejemplo n.º 13
0
Archivo: sq.cpp Proyecto: apaikan/myCub
int sqrl_main(int argc, char* argv[])
{
    
	HSQUIRRELVM v;
	SQInteger retval = 0;
	const SQChar *filename=NULL;
#if defined(_MSC_VER) && defined(_DEBUG)
	_CrtSetAllocHook(MemAllocHook);
#endif
	
	v=sq_open(1024);
	sq_setprintfunc(v,printfunc,errorfunc);

	sq_pushroottable(v);
    
	sqstd_register_bloblib(v);    
	sqstd_register_iolib(v);
	sqstd_register_mathlib(v);
 	   
    /*
     * TODO: system and string library should be implemented for nuttx 
     *       they need 'longjmp' and 'setjmp'. 
     */   
    //sqstd_register_stringlib(v);    
    //sqstd_register_systemlib(v);

	//aux library
	//sets error handlers
	sqstd_seterrorhandlers(v);

	//gets arguments
	switch(getargs(v,argc,argv,&retval))
	{
	case _INTERACTIVE:
		Interactive(v);
		break;
	case _DONE:
	case _ERROR:
	default: 
		break;
	}

	sq_close(v);
	
#if defined(_MSC_VER) && defined(_DEBUG)
	_getch();
	_CrtMemDumpAllObjectsSince( NULL );
#endif
	return retval;
    
    return 0;
}
Ejemplo n.º 14
0
int main(int argc, char* argv[])
{
	HSQUIRRELVM v;
	
	const SQChar *filename=NULL;
#if defined(_MSC_VER) && defined(_DEBUG)
	_CrtSetAllocHook(MemAllocHook);
#endif
	
	//v= sq_open(1024);
	v= sqobject::init();
	sq_setprintfunc(v,printfunc);

	sq_pushroottable(v);

	sqstd_register_bloblib(v);
	sqstd_register_iolib(v);
	sqstd_register_systemlib(v);
//	sqstd_register_mathlib(v);
//	sqstd_register_stringlib(v);

	//aux library
	//sets error handlers
//	sqstd_seterrorhandlers(v);

	sqobject::Object::registerClass();
	
	//gets arguments
	int ret;
	switch((ret = getargs(v,argc,argv)))
	{
	case _INTERACTIVE:
		Interactive(v);
		break;
	case _DONE:
	default: 
		break;
	}

	//sq_close(v);
	sqobject::done();
	
#if defined(_MSC_VER) && defined(_DEBUG)
	_getch();
	_CrtMemDumpAllObjectsSince( NULL );
#endif
	
	return ret == _ERROR ? -1 : 0;
}
Ejemplo n.º 15
0
void CMemLeakDetector::Disable()
{
	if(!m_HooksEnabled)
		return;

#if defined(PLATFORM_WINDOWS)
	_CrtSetAllocHook(m_OldHook);
	m_OldHook = NULL;
#else
#if defined(_DEBUG)
	RestoreHooks();
#endif
#endif
	m_HooksEnabled = false;
}
Ejemplo n.º 16
0
void CMemLeakDetector::Enable()
{
	if(m_HooksEnabled)
		return;

#if defined(PLATFORM_WINDOWS)
	m_OldHook = _CrtSetAllocHook(CrtAllocHook);
#else
#if defined(_DEBUG)
	SaveHooks();
	InstallHooks();
#endif
#endif
	m_HooksEnabled = true;
}
Ejemplo n.º 17
0
/***
*_CRT_ALLOC_HOOK_M _CrtSetAllocHook() - set client report hook
*
*Purpose:
*       set client alloc hook
*
*Entry:
*       _CRT_ALLOC_HOOK_M pfnNewHook - new alloc hook
*
*Exit:
*       return previous hook
*
*Exceptions:
*
*******************************************************************************/
_MRTIMP _CRT_ALLOC_HOOK_M __cdecl _CrtSetAllocHook
(
    _CRT_ALLOC_HOOK_M pfnNewHook
)
{
    if(_atexit_m_appdomain(_CrtAllocHook_managed_cleanup)!=0)
    {
        return NULL;
    }

    _CRT_ALLOC_HOOK_M pfnOldHook = (_CRT_ALLOC_HOOK_M) DecodePointer(__pfnAllocHookManaged);
    if (pfnNewHook)
    {
        __pfnAllocHookManaged = (_CRT_ALLOC_HOOK_M) EncodePointer(pfnNewHook);
        _CrtSetAllocHook((_CRT_ALLOC_HOOK)_CrtAllocHook_managed_thunk);
    }
    else
    {
        _CRT_ALLOC_HOOK_M enull = (_CRT_ALLOC_HOOK_M) EncodePointer(NULL)();
        __pfnAllocHookManaged = enull;
        _CrtSetAllocHook((_CRT_ALLOC_HOOK)NULL);
    }
    return pfnOldHook;
}
Ejemplo n.º 18
0
/*----------------------------------------------------------------------
|   PLT_Leak_Enable
+---------------------------------------------------------------------*/
void
PLT_Leak_Enable(void) 
{
#if defined(_DEBUG)
    /*
    * If you want VC to dump file name and line number of leaking resource
    * use #define _CRTDBG_MAP_ALLOC in suspected file (project)
    * and #include "crtdbg.h" in suspected file
    */
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF    |
               _CRTDBG_CHECK_ALWAYS_DF |
               _CRTDBG_LEAK_CHECK_DF);

_CrtSetAllocHook(PLT_Leak_AllocHook );

#endif
}
Ejemplo n.º 19
0
int main(int argc, char* argv[])
{
    HPSCRIPTVM v;
    PSInteger retval = 0;
#if defined(_MSC_VER) && defined(_DEBUG)
    _CrtSetAllocHook(MemAllocHook);
#endif

    v=ps_open(1024);
    ps_setprintfunc(v,printfunc,errorfunc);

    ps_pushroottable(v);

    psstd_register_bloblib(v);
    psstd_register_iolib(v);
    psstd_register_systemlib(v);
    psstd_register_mathlib(v);
    psstd_register_stringlib(v);
    psstd_register_exutillib(v);

    //aux library
    //sets error handlers
    psstd_seterrorhandlers(v);

    //gets arguments
    switch(getargs(v,argc,argv,&retval))
    {
    case _INTERACTIVE:
        Interactive(v);
        break;
    case _DONE:
    case _ERROR:
    default:
        break;
    }

    ps_close(v);

#if defined(_MSC_VER) && defined(_DEBUG)
    _getch();
    _CrtMemDumpAllObjectsSince( NULL );
#endif
    return retval;
}
Ejemplo n.º 20
0
	Bool32 LDPUMA_Done()
	{
		Bool32 rc = FALSE;
#ifdef _DEBUG
		_CrtDbgReport( _CRT_WARN,NULL,__LINE__,__FILE__,
				"LDPUMA_Done()\n");
		if(PrevAllocHook)
		_CrtSetAllocHook(PrevAllocHook);
#endif

		if(Done)
		rc = Done();
		if(hDPuma)
		{
			FreeLibrary(hDPuma);
			hDPuma = NULL;
		}
		return rc;
	}
Ejemplo n.º 21
0
void debugRemoveFreeHook(void)
{
#if defined(_WIN32) && defined(_DEBUG)
    _CrtSetAllocHook(lastCrtAllocHook);
#endif

#ifdef __GLIBC__
    __free_hook = lastFreeHook;
#endif

#ifdef __APPLE__
    malloc_zone_t* zone = malloc_default_zone();
    assert(zone != NULL);
    //remove the write protection from the zone struct
    if (zone->version >= 8) {
      vm_protect(mach_task_self(), (uintptr_t)zone, sizeof(*zone), 0, VM_PROT_READ | VM_PROT_WRITE);
    }
    zone->free = lastMallocZone.free;
    zone->free_definite_size = lastMallocZone.free_definite_size;
    if (zone->version >= 8) {
      vm_protect(mach_task_self(), (uintptr_t)zone, sizeof(*zone), 0, VM_PROT_READ);
    }
#endif
}
Ejemplo n.º 22
0
Archivo: misc.cpp Proyecto: xrmb/nxtv
 NXMemLog() 
 {
   m_fh = _fsopen("mem.log", "w+", SH_DENYNO);
   _CrtSetAllocHook(NXMemLog::allochook);
 }
Ejemplo n.º 23
0
	void debug_init()
	{
		_CrtSetAllocHook(allocation_hook);
	}
Ejemplo n.º 24
0
	Bool32 LDPUMA_Init(uint16_t wHightCode, Handle hStorage)
	{
		Bool32 rc = FALSE;
#ifdef _DEBUG
		_CrtDbgReport( _CRT_WARN,NULL,__LINE__,__FILE__,
				"LDPUMA_Init(%i,%x)\n",wHightCode, hStorage);
#endif
		hDPuma = LoadLibrary("DPUMA.DLL");
		if(hDPuma)
		{
			Init = (FNDPUMA_Init)GetProcAddress(hDPuma,"DPUMA_Init");
			Done = (FNDPUMA_Done)GetProcAddress(hDPuma,"DPUMA_Done");
			GetExportData = (FNDPUMA_GetExportData)GetProcAddress(hDPuma,"DPUMA_GetExportData");
			SetImportData = (FNDPUMA_SetImportData)GetProcAddress(hDPuma,"DPUMA_SetImportData"); //tanya
		}
		if(Init && GetExportData)
		{
			if(GetExportData(DPUMA_FNDPUMA_Console,&Console)&&
					GetExportData(DPUMA_FNDPUMA_CreateSnap,&CreateSnap)&&
					GetExportData(DPUMA_FNDPUMA_DestroySnap,&DestroySnap)&&
					GetExportData(DPUMA_FNDPUMA_Stop,&Stop)&&
					GetExportData(DPUMA_FNDPUMA_IsActive,&IsActive)&&
					GetExportData(DPUMA_FNDPUMA_StatusLine,&StatusLine)&&
					GetExportData(DPUMA_FNDPUMA_Registry,&Registry)&&
					GetExportData(DPUMA_FNDPUMA_Skip,&Skip)&&
					GetExportData(DPUMA_FNDPUMA_StartLoop,&StartLoop)&&
					GetExportData(DPUMA_FNDPUMA_LoopNext,&LoopNext)&&
					GetExportData(DPUMA_FNDPUMA_CreateWindow,&fCreateWindow)&&
					GetExportData(DPUMA_FNDPUMA_MessageBoxOk,&MessageBoxOk)&&
					GetExportData(DPUMA_FNDPUMA_MessageBoxYesNo,&MessageBoxYesNo)&&
					GetExportData(DPUMA_FNDPUMA_WaitUserInput,&WaitUserInput)&&
					GetExportData(DPUMA_FNDPUMA_DrawLine,&DrawLine)&&
					GetExportData(DPUMA_FNDPUMA_DrawRect,&DrawRect)&&
					GetExportData(DPUMA_FNDPUMA_DrawLineTip,&DrawLineTip)&&
					GetExportData(DPUMA_FNDPUMA_DrawRectTip,&DrawRectTip)&&
					GetExportData(DPUMA_FNDPUMA_DeleteRects,&DeleteRects)&&
					GetExportData(DPUMA_FNDPUMA_DeleteLines,&DeleteLines)&&
					GetExportData(DPUMA_FNDPUMA_GetUserPoint,&GetUserPoint)&&
					GetExportData(DPUMA_FNDPUMA_GetUserRect,&GetUserRect)&&
					GetExportData(DPUMA_FNDPUMA_UpdateView,&UpdateView)&&
					GetExportData(DPUMA_FNDPUMA_DrawRaster,&DrawRaster)&&
					GetExportData(DPUMA_FNDPUMA_ZoomToRect,&ZoomToRect)&&
					GetExportData(DPUMA_FNDPUMA_RasterHeader,&RasterHeader)&&
					GetExportData(DPUMA_FNDPUMA_DrawFocusRect,&fnDrawFocusRect)&&
					GetExportData(DPUMA_FNDPUMA_RegVariable,&RegVariable)&&
					GetExportData(DPUMA_FNDPUMA_UnregVariable,&UnregVariable)&&
					GetExportData(DPUMA_FNDPUMA_GetDIBptr,&GetDIBptr)&&
					GetExportData(DPUMA_FNDPUMA_DrawString,&DrawString)&&
					GetExportData(DPUMA_FNDPUMA_DeleteStrings,&DeleteStrings)&&
					GetExportData(DPUMA_FNDPUMA_SetCallbackWindowProc,&SetCallbackWindowProc)&&
					GetExportData(DPUMA_FNDPUMA_DeviceToImage,&DeviceToImage)&&
					GetExportData(DPUMA_FNDPUMA_ImageToDevice,&ImageToDevice)&&
					GetExportData(DPUMA_FNDPUMA_SetCallbackMainFrameWindowProc,&SetCallbackMainFrameWindowProc)&&
					GetExportData(DPUMA_FNDPUMA_DestroyWindow,&fDestroyWindow)&&
					GetExportData(DPUMA_FNDPUMA_SendWindow,&SendWindow)&&
					GetExportData(DPUMA_FNDPUMA_SendMainWnd,&SendMainWnd)&&
					GetExportData(DPUMA_FNDPUMA_CSTR_Monitor,&cstr_Monitor)&&
					GetExportData(DPUMA_FNDPUMA_CSTR_GetPosition,&cstr_GetPosition)&&
					GetExportData(DPUMA_FNDPUMA_CSTR_SetPosition,&cstr_SetPosition)&&
					GetExportData(DPUMA_FNDPUMA_DestroyRasterWnd,&DestroyRasterWnd)&&
					GetExportData(DPUMA_FNDPUMA_CSTR_GetLength,&cstr_GetLength)&&
					GetExportData(DPUMA_FNDPUMA_ShowCutPoint,&ShowCutPoint)&&
					GetExportData(DPUMA_FNDPUMA_GetRasterPixel,&GetRasterPixel)&&
					GetExportData(DPUMA_FNDPUMA_CSTR_Update,&cstr_Update)&&
					GetExportData(DPUMA_FNDPUMA_SkipEx,&SkipEx)&&
					GetExportData(DPUMA_FNDPUMA_OpenFile,&fOpenFile)&&
					GetExportData(DPUMA_FNDPUMA_GetFileName,&fGetFileName)&&
					GetExportData(DPUMA_FNDPUMA_HandLayout,&fHandLayout)&&
					GetExportData(DPUMA_FNDPUMA_LockImage,&fLockImage)&&
					GetExportData(DPUMA_FNDPUMA_RegistryHelp,&RegistryHelp)&&
					GetExportData(DPUMA_FNDPUMA_SaveFile,&fSaveFile)&&
					GetExportData(DPUMA_FNDPUMA_ProgressStart, &fProgressStart )&&
					GetExportData(DPUMA_FNDPUMA_ProgressFinish,&fProgressFinish)&&
					GetExportData(DPUMA_FNDPUMA_ProgressStep, &fProgressStep )&&
					GetExportData(DPUMA_FNDPUMA_SetConsoleProperty, &fSetConsoleProperty )&&
					GetExportData(DPUMA_FNDPUMA_CreateHistogramm, &fCreateHistogramm )&&
					GetExportData(DPUMA_FNDPUMA_AddPointToHistogramm, &fAddPointToHistogramm )&&
					GetExportData(DPUMA_FNDPUMA_DoHistogramm, &fDoHistogramm )&&
					GetExportData(DPUMA_FNDPUMA_DestroyHistogramm, &fDestroyHistogramm )&&
					GetExportData(DPUMA_FNDPUMA_GetWindowHandle,&fGetWindowHandle)&&
					GetExportData(DPUMA_FNDPUMA_GetPrevSkipOwner,&fGetPrevSkipOwner)&&
					GetExportData(DPUMA_FNDPUMA_AllocHook,&fAllocHook)&&
					GetExportData(DPUMA_FNDPUMA_ConsoleClear,&fConsoleClear)&&
					GetExportData(DPUMA_FNDPUMA_ConsoleGetCurLine,&fConsoleGetCurLine)&&
					GetExportData(DPUMA_FNDPUMA_SetFileName,&fSetFileName )&&
					GetExportData(DPUMA_FNDPUMA_FOpen,&fFOpen )&&
					GetExportData(DPUMA_FNDPUMA_FClose,&fFClose)&&
					GetExportData(DPUMA_FNDPUMA_FPrintf1024,&fFPrintf1024)&&
					GetExportData(DPUMA_FNDPUMA_FPuts,&fFPuts)&&
					GetExportData(DPUMA_FNDPUMA_RasterText,&RasterText)&&
					SetImportData != NULL/*tanya*/
			)
			{
				rc = Init(wHightCode,hStorage);
				if(rc)
				{
#ifdef _DEBUG
					// На случай, если вызывается не один раз.
					_CRT_ALLOC_HOOK pHook = _CrtSetAllocHook(__DPUMA__AllocHook__);
					if(__DPUMA__AllocHook__ != pHook)
					PrevAllocHook = pHook;
#endif
					fCreateWindow("Main",NULL);
					LDPUMA_Registry(&hWriteFile,"Выполнять отладочную запись в файл.",NULL);
					LDPUMA_RegistryHelp(hWriteFile,"Разрешает отладочную запись функциями DPUMA.",FALSE);
				}
			}
		}
		return rc;
	}
Ejemplo n.º 25
0
void setupHook()
{
    pfnOldCrtAllocHook = _CrtSetAllocHook(crtAllocationHook);
}
Ejemplo n.º 26
0
			RemoveAlloc(pvData, nSize, lRequest);
		}

		// clear the new caller
		g_newFile = "";

		g_inAllocHook = false;
	}

	return TRUE;
}

static InitFunction initFunction([] ()
{
	_CrtSetAllocHook(CrtAllocHook);
}, -100);

static uint32_t g_lastTrackTime;

void StoreAlloc(void* ptr, size_t size, long reqID, const char* newFile, const char* newFunc, size_t newLine)
{
	if (!g_memCritSec.DebugInfo)
	{
		g_memorySizes = new std::map<long, size_t>();
		g_newAllocations = new std::set<long>();

		InitializeCriticalSectionAndSpinCount(&g_memCritSec, 1000);
	}

	InterlockedAdd(&g_globalTrackedMemory, size);
Ejemplo n.º 27
0
static void alloc_hook_initialize()
{
	prev_hook = _CrtSetAllocHook(crt_alloc_hook);
}
Ejemplo n.º 28
0
int main(int argc, char* argv[])
{
#ifdef _DEBUG
  // Setup the debug options
  _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF 
    | _CRTDBG_LEAK_CHECK_DF //Check for memory leaks on app exit
    );//| _CRTDBG_CHECK_ALWAYS_DF);
  _CrtSetAllocHook(YourAllocHook);	
#endif

  // Read in Version Infomation
  CFileVersionInfo ver;
  ver.Open(GetModuleHandle(NULL));
  TCHAR displayName[256];
  _sntprintf(displayName, 255, _T("Munin Node for Windows %i.%i.%i"), ver.GetFileVersionMajor(), ver.GetFileVersionMinor(), ver.GetFileVersionQFE());

  // Load Configuration
  // Get the executable file path
  char szConfigFilePath[MAX_PATH];
  ::GetModuleFileNameA(NULL, szConfigFilePath, MAX_PATH);
  PathRemoveFileSpecA(szConfigFilePath);
  PathAppendA(szConfigFilePath, "\\munin-node.ini");
  g_Config.SetPath(szConfigFilePath);
  g_Config.ReadFile();

  // Prepare Service modules
  _Module.Init(_T("munin-node"), _T("Munin Node for Windows"));
  _Module.m_bService = TRUE;  

  // Parse arguments
  if (argc > 1)
  {
    char seps[] = "-/";
    char *pToken;

    pToken = strtok(argv[1], seps);
    while (pToken)
    {
      if (!stricmp(pToken, "install"))
      {
        return !_Module.Install();
      }
      else if (!stricmp(pToken, "uninstall"))
      {
        return !_Module.Uninstall();
      }
      else if (!stricmp(pToken, "quiet"))
      {
        FreeConsole();
      }
      else if (!stricmp(pToken, "unattended"))
      {
        _Module.SetQuiet(true);
      }
      else if (!stricmp(pToken, "run"))
      {
        _Module.m_bService = FALSE;
      }
      else if (!stricmp(pToken, "help") || !stricmp(pToken, "h") || !stricmp(pToken, "?"))
      {
        printf("%s\n", _Module.GetServiceDisplayName());
        printf("Usage:\n");
        printf("  -install    Install the 'Munin Node' service.\n");
        printf("  -uninstall  Removes the 'Munin Node' service.\n");
        printf("  -quiet      Close the console window, running in the background.\n");
        printf("  -run        Run as a normal program, rather than a service.\n");

        return 1;
      }
      pToken = strtok(NULL, seps);			
    }
  }	

  _Module.Start();

  return 0;
}