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.

117 lines
2.6 KiB

  1. #include "ctlspriv.h"
  2. // Define some things for debug.h
  3. //
  4. #define SZ_DEBUGINI "ccshell.ini"
  5. #define SZ_DEBUGSECTION "comctl32"
  6. #define SZ_MODULE "COMCTL32"
  7. #define DECLARE_DEBUG
  8. #include <debug.h>
  9. //========== Memory Management =============================================
  10. void * WINAPI Alloc(long cb)
  11. {
  12. // I will assume that this is the only one that needs the checks to
  13. // see if the heap has been previously created or not
  14. return (void *)LocalAlloc(LPTR, cb);
  15. }
  16. void * WINAPI ReAlloc(void * pb, long cb)
  17. {
  18. if (pb == NULL)
  19. return Alloc(cb);
  20. return (void *)LocalReAlloc((HLOCAL)pb, cb, LMEM_ZEROINIT | LMEM_MOVEABLE);
  21. }
  22. BOOL WINAPI Free(void * pb)
  23. {
  24. return (LocalFree((HLOCAL)pb) == NULL);
  25. }
  26. DWORD_PTR WINAPI GetSize(void * pb)
  27. {
  28. return LocalSize((HLOCAL)pb);
  29. }
  30. //----------------------------------------------------------------------------
  31. // The following functions are for debug only and are used to try to
  32. // calculate memory usage.
  33. //
  34. #ifdef DEBUG
  35. typedef struct _HEAPTRACE
  36. {
  37. DWORD cAlloc;
  38. DWORD cFailure;
  39. DWORD cReAlloc;
  40. ULONG_PTR cbMaxTotal;
  41. DWORD cCurAlloc;
  42. ULONG_PTR cbCurTotal;
  43. } HEAPTRACE;
  44. HEAPTRACE g_htShell = {0}; // Start of zero...
  45. LPVOID WINAPI ControlAlloc(HANDLE hheap, DWORD cb)
  46. {
  47. LPVOID lp = HeapAlloc(hheap, HEAP_ZERO_MEMORY, cb);;
  48. if (lp == NULL)
  49. {
  50. g_htShell.cFailure++;
  51. return NULL;
  52. }
  53. // Update counts.
  54. g_htShell.cAlloc++;
  55. g_htShell.cCurAlloc++;
  56. g_htShell.cbCurTotal += cb;
  57. if (g_htShell.cbCurTotal > g_htShell.cbMaxTotal)
  58. g_htShell.cbMaxTotal = g_htShell.cbCurTotal;
  59. return lp;
  60. }
  61. LPVOID WINAPI ControlReAlloc(HANDLE hheap, LPVOID pb, DWORD cb)
  62. {
  63. LPVOID lp;
  64. SIZE_T cbOld;
  65. cbOld = HeapSize(hheap, 0, pb);
  66. lp = HeapReAlloc(hheap, HEAP_ZERO_MEMORY, pb,cb);
  67. if (lp == NULL)
  68. {
  69. g_htShell.cFailure++;
  70. return NULL;
  71. }
  72. // Update counts.
  73. g_htShell.cReAlloc++;
  74. g_htShell.cbCurTotal += cb - cbOld;
  75. if (g_htShell.cbCurTotal > g_htShell.cbMaxTotal)
  76. g_htShell.cbMaxTotal = g_htShell.cbCurTotal;
  77. return lp;
  78. }
  79. BOOL WINAPI ControlFree(HANDLE hheap, LPVOID pb)
  80. {
  81. SIZE_T cbOld = HeapSize(hheap, 0, pb);
  82. BOOL fRet = HeapFree(hheap, 0, pb);
  83. if (fRet)
  84. {
  85. // Update counts.
  86. g_htShell.cCurAlloc--;
  87. g_htShell.cbCurTotal -= cbOld;
  88. }
  89. return(fRet);
  90. }
  91. SIZE_T WINAPI ControlSize(HANDLE hheap, LPVOID pb)
  92. {
  93. return (DWORD) HeapSize(hheap, 0, pb);
  94. }
  95. #endif // DEBUG