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.

129 lines
3.0 KiB

  1. //-----------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation, 1997 - 1999
  3. //
  4. // memory.c
  5. //
  6. // The RPC Proxy uses its own heap.
  7. //
  8. //
  9. // History:
  10. //
  11. // Edward Reus 06-23-97 Initial Version.
  12. //-----------------------------------------------------------------
  13. #include <sysinc.h>
  14. #include <rpc.h>
  15. #include <rpcdce.h>
  16. #include <winsock2.h>
  17. #include <httpfilt.h>
  18. #include <httpext.h>
  19. #include "ecblist.h"
  20. #include "filter.h"
  21. //-----------------------------------------------------------------
  22. // Globals:
  23. //-----------------------------------------------------------------
  24. HANDLE g_hHeap = NULL;
  25. //-----------------------------------------------------------------
  26. // MemInitialize()
  27. //
  28. // Creates a heap to be used by MemAllocate() and MemFree().
  29. //
  30. // Note: You don't need to call this function, it will be called
  31. // automatically by MemAllocate().
  32. //-----------------------------------------------------------------
  33. BOOL MemInitialize( DWORD *pdwStatus )
  34. {
  35. SYSTEM_INFO SystemInfo;
  36. *pdwStatus = 0;
  37. if (!g_hHeap)
  38. {
  39. GetSystemInfo(&SystemInfo);
  40. g_hHeap = HeapCreate(0L,SystemInfo.dwPageSize,0L);
  41. if (!g_hHeap)
  42. {
  43. *pdwStatus = GetLastError();
  44. #ifdef DBG_ERROR
  45. DbgPrint("MemInitialize(): HeapCreate() failed: %d\n",*pdwStatus);
  46. #endif
  47. return FALSE;
  48. }
  49. }
  50. return TRUE;
  51. }
  52. //-----------------------------------------------------------------
  53. // MemAllocate()
  54. //
  55. // Allocate a chunk of memory of dwSize bytes.
  56. //-----------------------------------------------------------------
  57. void *MemAllocate( DWORD dwSize )
  58. {
  59. DWORD dwStatus;
  60. void *pMem;
  61. if (!g_hHeap)
  62. {
  63. if (!MemInitialize(&dwStatus))
  64. {
  65. return NULL;
  66. }
  67. }
  68. pMem = HeapAlloc(g_hHeap,0L,dwSize);
  69. return pMem;
  70. }
  71. //-----------------------------------------------------------------
  72. // MemFree()
  73. //
  74. // Free memory allocated by MemAllocate().
  75. //-----------------------------------------------------------------
  76. void *MemFree( void *pMem )
  77. {
  78. if (g_hHeap)
  79. {
  80. #ifdef DBG_ERROR
  81. if (!HeapFree(g_hHeap,0L,pMem))
  82. {
  83. DbgPrint("MemFree(): HeapFree() failed: %d\n",GetLastError());
  84. }
  85. #else
  86. HeapFree(g_hHeap,0L,pMem);
  87. #endif
  88. }
  89. #ifdef DBG_ERROR
  90. else
  91. {
  92. DbgPrint("MemFree(): Called on uninitialized Heap.\n");
  93. }
  94. #endif
  95. return NULL;
  96. }
  97. //-----------------------------------------------------------------
  98. // MemTerminate()
  99. //
  100. //-----------------------------------------------------------------
  101. void MemTerminage()
  102. {
  103. if (g_hHeap)
  104. {
  105. #ifdef DBG_ERROR
  106. if (!HeapDestroy(g_hHeap))
  107. {
  108. DbgPrint("MemTerminate(): HeapDestroy() failed: %d\n",GetLastError());
  109. }
  110. #else
  111. HeapDestroy(g_hHeap);
  112. #endif
  113. }
  114. }