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.

194 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. mem.c
  5. Abstract:
  6. Contains memory allocation routines for SNMP master agent.
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. 10-Feb-1997 DonRyan
  11. Rewrote to implement SNMPv2 support.
  12. --*/
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // //
  15. // Include files //
  16. // //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include "globals.h"
  19. #include "mem.h"
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // //
  22. // Private definitions //
  23. // //
  24. ///////////////////////////////////////////////////////////////////////////////
  25. #define AGENT_HEAP_FLAGS 0
  26. #define AGENT_HEAP_INITIAL_SIZE 0xffff
  27. #define AGENT_HEAP_MAXIMUM_SIZE 0
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // //
  30. // Global variables //
  31. // //
  32. ///////////////////////////////////////////////////////////////////////////////
  33. HANDLE g_hAgentHeap = NULL;
  34. ///////////////////////////////////////////////////////////////////////////////
  35. // //
  36. // Public procudures //
  37. // //
  38. ///////////////////////////////////////////////////////////////////////////////
  39. BOOL
  40. AgentHeapCreate(
  41. )
  42. /*++
  43. Routine Description:
  44. Creates private heap for master agent private structures.
  45. Arguments:
  46. None.
  47. Return Values:
  48. Returns true if successful.
  49. --*/
  50. {
  51. // create master agent heap
  52. g_hAgentHeap = HeapCreate(
  53. AGENT_HEAP_FLAGS,
  54. AGENT_HEAP_INITIAL_SIZE,
  55. AGENT_HEAP_MAXIMUM_SIZE
  56. );
  57. // validate heap handle
  58. if (g_hAgentHeap == NULL) {
  59. SNMPDBG((
  60. SNMP_LOG_ERROR,
  61. "SNMP: SVC: error %d creating agent heap.\n",
  62. GetLastError()
  63. ));
  64. }
  65. // return success if created
  66. return (g_hAgentHeap != NULL);
  67. }
  68. BOOL
  69. AgentHeapDestroy(
  70. )
  71. /*++
  72. Routine Description:
  73. Destroys private heap for master agent private structures.
  74. Arguments:
  75. None.
  76. Return Values:
  77. Returns true if successful.
  78. --*/
  79. {
  80. // validate handle
  81. if (g_hAgentHeap != NULL) {
  82. // release heap handle
  83. HeapDestroy(g_hAgentHeap);
  84. // re-initialize
  85. g_hAgentHeap = NULL;
  86. }
  87. return TRUE;
  88. }
  89. LPVOID
  90. AgentMemAlloc(
  91. UINT nBytes
  92. )
  93. /*++
  94. Routine Description:
  95. Allocates memory from master agent's private heap.
  96. Arguments:
  97. None.
  98. Return Values:
  99. Returns true if successful.
  100. --*/
  101. {
  102. // allocate memory from private heap (and initialize)
  103. return HeapAlloc(g_hAgentHeap, HEAP_ZERO_MEMORY, nBytes);
  104. }
  105. VOID
  106. AgentMemFree(
  107. LPVOID pMem
  108. )
  109. /*++
  110. Routine Description:
  111. Frees memory from master agent's private heap.
  112. Arguments:
  113. pMem - pointer to memory block to release.
  114. Return Values:
  115. Returns true if successful.
  116. --*/
  117. {
  118. // validate pointer
  119. if (pMem != NULL) {
  120. // release agent memory
  121. HeapFree(g_hAgentHeap, 0, pMem);
  122. }
  123. }