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.

156 lines
3.8 KiB

  1. /*****************************************************************************
  2. *
  3. * ftpmi.cpp - IMalloc interface for allocing pidls
  4. *
  5. *****************************************************************************/
  6. #include "priv.h"
  7. #include "ftpmi.h"
  8. /*****************************************************************************
  9. * IMalloc::Alloc
  10. *****************************************************************************/
  11. LPVOID CMallocItem::Alloc(ULONG cbSize)
  12. {
  13. WORD cbActualSize = sizeof(DELEGATEITEMID) - 1 + cbSize;
  14. PDELEGATEITEMID pidl = (PDELEGATEITEMID)SHAlloc(cbActualSize + 2);
  15. if (pidl)
  16. {
  17. pidl->cbSize = cbActualSize;
  18. pidl->wOuter = 0x6646; // "Ff"
  19. pidl->cbInner = (WORD)cbSize;
  20. *(WORD *)&(((BYTE *)pidl)[cbActualSize]) = 0;
  21. }
  22. return pidl;
  23. }
  24. /*****************************************************************************
  25. * IMalloc::Realloc
  26. *****************************************************************************/
  27. LPVOID CMallocItem::Realloc(LPVOID pv, ULONG cb)
  28. {
  29. return NULL;
  30. }
  31. /*****************************************************************************
  32. * IMalloc::Free
  33. *****************************************************************************/
  34. void CMallocItem::Free(LPVOID pv)
  35. {
  36. SHFree(pv);
  37. }
  38. /*****************************************************************************
  39. * IMalloc::GetSize
  40. *****************************************************************************/
  41. ULONG CMallocItem::GetSize(LPVOID pv)
  42. {
  43. return (ULONG)-1;
  44. }
  45. /*****************************************************************************
  46. * IMalloc::DidAlloc
  47. *****************************************************************************/
  48. int CMallocItem::DidAlloc(LPVOID pv)
  49. {
  50. return -1;
  51. }
  52. /*****************************************************************************
  53. * IMalloc::HeapMinimize
  54. *****************************************************************************/
  55. void CMallocItem::HeapMinimize(void)
  56. {
  57. NULL;
  58. }
  59. /*****************************************************************************
  60. * CMallocItem_Create
  61. *****************************************************************************/
  62. HRESULT CMallocItem_Create(IMalloc ** ppm)
  63. {
  64. HRESULT hres = E_OUTOFMEMORY;
  65. CMallocItem * pmi = new CMallocItem();
  66. if (pmi)
  67. {
  68. hres = pmi->QueryInterface(IID_IMalloc, (LPVOID *) ppm);
  69. pmi->Release();
  70. }
  71. return hres;
  72. }
  73. /****************************************************\
  74. Constructor
  75. \****************************************************/
  76. CMallocItem::CMallocItem() : m_cRef(1)
  77. {
  78. DllAddRef();
  79. // This needs to be allocated in Zero Inited Memory.
  80. // Assert that all Member Variables are inited to Zero.
  81. LEAK_ADDREF(LEAK_CMallocItem);
  82. }
  83. /****************************************************\
  84. Destructor
  85. \****************************************************/
  86. CMallocItem::~CMallocItem()
  87. {
  88. DllRelease();
  89. LEAK_DELREF(LEAK_CMallocItem);
  90. }
  91. //===========================
  92. // *** IUnknown Interface ***
  93. //===========================
  94. ULONG CMallocItem::AddRef()
  95. {
  96. m_cRef++;
  97. return m_cRef;
  98. }
  99. ULONG CMallocItem::Release()
  100. {
  101. ASSERT(m_cRef > 0);
  102. m_cRef--;
  103. if (m_cRef > 0)
  104. return m_cRef;
  105. delete this;
  106. return 0;
  107. }
  108. HRESULT CMallocItem::QueryInterface(REFIID riid, void **ppvObj)
  109. {
  110. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IMalloc))
  111. {
  112. *ppvObj = SAFECAST(this, IMalloc *);
  113. }
  114. else
  115. {
  116. TraceMsg(TF_FTPQI, "CMallocItem::QueryInterface() failed.");
  117. *ppvObj = NULL;
  118. return E_NOINTERFACE;
  119. }
  120. AddRef();
  121. return S_OK;
  122. }