[vlc-devel] [PATCH 2/2] ActiveX: fixed memory leak on multiple DllGetClassObject call

Sergey Radionov rsatom at gmail.com
Sat Sep 29 14:43:28 CEST 2012


---
 activex/plugin.cpp | 10 ++++++----
 activex/plugin.h   |  1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/activex/plugin.cpp b/activex/plugin.cpp
index ca3932d..8f9896d 100644
--- a/activex/plugin.cpp
+++ b/activex/plugin.cpp
@@ -94,6 +94,7 @@ static LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wPar
 
 VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid) :
     _p_class_ref(p_class_ref),
+    _class_ref(0),
     _hinstance(hInstance),
     _classid(rclsid),
     _inplace_picture(NULL)
@@ -166,18 +167,19 @@ STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
 
 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
 {
-    return InterlockedIncrement(_p_class_ref);
+    InterlockedIncrement(_p_class_ref);
+    return ++_class_ref;
 };
 
 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
 {
-    ULONG refcount = InterlockedDecrement(_p_class_ref);
-    if( 0 == refcount )
+    InterlockedDecrement(_p_class_ref);
+    if( 0 == (--_class_ref) )
     {
         delete this;
         return 0;
     }
-    return refcount;
+    return _class_ref;
 };
 
 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
diff --git a/activex/plugin.h b/activex/plugin.h
index 06fb5c0..7569c65 100644
--- a/activex/plugin.h
+++ b/activex/plugin.h
@@ -70,6 +70,7 @@ protected:
 private:
 
     LPLONG      _p_class_ref;
+    ULONG       _class_ref;
     HINSTANCE   _hinstance;
     CLSID       _classid;
     ATOM        _inplace_wndclass_atom;
-- 
1.7.11.msysgit.1




More information about the vlc-devel mailing list