jmemleak.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef JMEMLEAK_H
  14. #define JMEMLEAK_H
  15. #if (defined WIN32) || (defined _WIN32) || (defined __WIN32__) || (defined WIN64) || (defined _WIN64) || (defined __WIN64__)
  16. #ifdef _DEBUG
  17. #define _CRTDBG_MAP_ALLOC
  18. #include <crtdbg.h>
  19. #include <signal.h>
  20. #include <stdio.h>
  21. #include <process.h>
  22. void __cdecl IntHandler(int)
  23. {
  24. #ifndef USING_MPATROL
  25. // Don't care about memory leaks on a ctrl-Break!
  26. int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
  27. tmpFlag &= ~_CRTDBG_LEAK_CHECK_DF;
  28. _CrtSetDbgFlag( tmpFlag );
  29. #endif //USING_MPATROL
  30. _exit(2);
  31. }
  32. int __init()
  33. {
  34. signal(SIGINT, IntHandler);
  35. #ifndef USING_MPATROL
  36. int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
  37. tmpFlag |= _CRTDBG_LEAK_CHECK_DF;// | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF ;
  38. _CrtSetDbgFlag( tmpFlag );
  39. #endif //USING_MPATROL
  40. return 0;
  41. }
  42. static int __doinit = __init();
  43. #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
  44. #endif
  45. #endif
  46. #endif