Browse Source

Using IMalloc::Free instead of delete for Release.

Adam Yang 8 years ago
parent
commit
2fea86ac2b
1 changed files with 7 additions and 1 deletions
  1. 7 1
      include/dxc/Support/microcom.h

+ 7 - 1
include/dxc/Support/microcom.h

@@ -93,6 +93,11 @@ inline T *CreateOnMalloc(IMalloc * pMalloc, Args&&... args) {
   return (T *)P; \
 }
 
+template<typename T>
+void DxcCallDestructor(T *obj) {
+  obj->~T();
+}
+
 // The "TM" version keep an IMalloc field that, if not null, indicate
 // ownership of 'this' and of any allocations used during release.
 #define DXC_MICROCOM_TM_REF_FIELDS() \
@@ -104,7 +109,8 @@ inline T *CreateOnMalloc(IMalloc * pMalloc, Args&&... args) {
       ULONG result = InterlockedDecrement(&m_dwRef); \
       if (result == 0) { \
         CComPtr<IMalloc> pTmp(m_pMalloc); \
-        DxcThreadMalloc M(pTmp); delete this; \
+        DxcCallDestructor(this); \
+        pTmp->Free(this); \
       } \
       return result; \
     }