Zebediah Figura : compobj: Implement reference counting for the standard allocator.

Alexandre Julliard julliard at winehq.org
Wed Jan 22 14:52:58 CST 2020


Module: wine
Branch: master
Commit: bfaf90137e4a2fb2d139df6e398f04c826e02405
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=bfaf90137e4a2fb2d139df6e398f04c826e02405

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Wed Jan 15 00:24:33 2020 -0600

compobj: Implement reference counting for the standard allocator.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/compobj.dll16/compobj.c          | 34 ++++++++++++++++++++--------------
 dlls/compobj.dll16/compobj.dll16.spec |  2 +-
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/dlls/compobj.dll16/compobj.c b/dlls/compobj.dll16/compobj.c
index ff82f9087b..a634ebe637 100644
--- a/dlls/compobj.dll16/compobj.c
+++ b/dlls/compobj.dll16/compobj.c
@@ -111,8 +111,8 @@ static SEGPTR compobj_malloc;
 
 typedef struct
 {
-        IMalloc16 IMalloc16_iface;
-        DWORD     ref;
+    IMalloc16 IMalloc16_iface;
+    LONG refcount;
 } IMalloc16Impl;
 
 static inline IMalloc16Impl *impl_from_IMalloc16(IMalloc16 *iface)
@@ -139,21 +139,28 @@ HRESULT CDECL IMalloc16_fnQueryInterface(IMalloc16* iface,REFIID refiid,LPVOID *
 /******************************************************************************
  *		IMalloc16_AddRef	[COMPOBJ.501]
  */
-ULONG CDECL IMalloc16_fnAddRef(IMalloc16* iface) {
-        IMalloc16Impl *This = impl_from_IMalloc16(iface);
-
-	TRACE("(%p)->AddRef()\n",This);
-	return 1; /* cannot be freed */
+ULONG CDECL IMalloc16_fnAddRef(IMalloc16 *iface)
+{
+    IMalloc16Impl *malloc = impl_from_IMalloc16(iface);
+    ULONG refcount = InterlockedIncrement(&malloc->refcount);
+    TRACE("%p increasing refcount to %u.\n", malloc, refcount);
+    return refcount;
 }
 
 /******************************************************************************
  *		IMalloc16_Release	[COMPOBJ.502]
  */
-ULONG CDECL IMalloc16_fnRelease(IMalloc16* iface) {
-        IMalloc16Impl *This = impl_from_IMalloc16(iface);
-
-	TRACE("(%p)->Release()\n",This);
-	return 1; /* cannot be freed */
+ULONG CDECL IMalloc16_fnRelease(SEGPTR iface)
+{
+    IMalloc16Impl *malloc = impl_from_IMalloc16(MapSL(iface));
+    ULONG refcount = InterlockedDecrement(&malloc->refcount);
+    TRACE("%p decreasing refcount to %u.\n", malloc, refcount);
+    if (!refcount)
+    {
+        UnMapLS(iface);
+        HeapFree(GetProcessHeap(), 0, malloc);
+    }
+    return refcount;
 }
 
 /******************************************************************************
@@ -257,11 +264,10 @@ static SEGPTR IMalloc16_Constructor(void)
         msegvt16 = MapLS( &vt16 );
     }
     This->IMalloc16_iface.lpVtbl = msegvt16;
-    This->ref = 1;
+    This->refcount = 1;
     return MapLS(This);
 }
 
-
 /******************************************************************************
  *           CoBuildVersion [COMPOBJ.1]
  */
diff --git a/dlls/compobj.dll16/compobj.dll16.spec b/dlls/compobj.dll16/compobj.dll16.spec
index 8c0456504d..04d17155ae 100644
--- a/dlls/compobj.dll16/compobj.dll16.spec
+++ b/dlls/compobj.dll16/compobj.dll16.spec
@@ -209,7 +209,7 @@
 # WINE internal relays (for Win16 interfaces)
 500 cdecl IMalloc16_QueryInterface(ptr ptr ptr) IMalloc16_fnQueryInterface
 501 cdecl IMalloc16_AddRef(ptr) IMalloc16_fnAddRef
-502 cdecl IMalloc16_Release(ptr) IMalloc16_fnRelease
+502 cdecl IMalloc16_Release(segptr) IMalloc16_fnRelease
 503 cdecl IMalloc16_Alloc(ptr long) IMalloc16_fnAlloc
 504 cdecl IMalloc16_Realloc(ptr segptr long) IMalloc16_fnRealloc
 505 cdecl IMalloc16_Free(ptr segptr) IMalloc16_fnFree




More information about the wine-cvs mailing list