Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
1.9 KiB

  1. //***************************************************************************
  2. //
  3. // PROVEXPT.CPP
  4. //
  5. // Module: OLE MS Provider Framework
  6. //
  7. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  8. //
  9. //***************************************************************************
  10. #include "precomp.h"
  11. #include <malloc.h>
  12. #ifdef COMMONALLOC
  13. #include <corepol.h>
  14. #include <arena.h>
  15. #endif
  16. #ifdef THROW_AFTER_N_NEW
  17. UINT g_test = 0;
  18. void *operator new( size_t n)
  19. {
  20. void *ptr = (void*) LocalAlloc(LMEM_FIXED, n);
  21. if (ptr && (g_test < 250))
  22. {
  23. g_test++;
  24. }
  25. else
  26. {
  27. g_test = 0;
  28. throw Heap_Exception(Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  29. }
  30. return ptr;
  31. }
  32. #else //THROW_AFTER_N_NEW
  33. #ifdef COMMONALLOC
  34. void *operator new( size_t n)
  35. {
  36. void *ptr = (void*) CWin32DefaultArena::WbemMemAlloc(n);
  37. if (!ptr)
  38. {
  39. throw Heap_Exception(Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  40. }
  41. return ptr;
  42. }
  43. #else
  44. void* __cdecl operator new( size_t n)
  45. {
  46. void *ptr = malloc( n );
  47. if (!ptr)
  48. {
  49. throw Heap_Exception(Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  50. }
  51. return ptr;
  52. }
  53. void* __cdecl operator new[]( size_t n)
  54. {
  55. void *ptr = malloc( n );
  56. if (!ptr)
  57. {
  58. throw Heap_Exception(Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  59. }
  60. return ptr;
  61. }
  62. #endif // COMMONALLOC
  63. #endif //THROW_AFTER_N_NEW
  64. #ifdef COMMONALLOC
  65. void operator delete( void *ptr )
  66. {
  67. if (ptr)
  68. {
  69. CWin32DefaultArena::WbemMemFree(ptr);
  70. }
  71. }
  72. #else
  73. void __cdecl operator delete( void *ptr )
  74. {
  75. if (ptr)
  76. {
  77. free( ptr );
  78. }
  79. }
  80. void __cdecl operator delete[]( void *ptr )
  81. {
  82. if (ptr)
  83. {
  84. free( ptr );
  85. }
  86. }
  87. #endif //COMMONALLOC