oleaut32: Fix some reference leaks.
authorPiotr Caban <piotr@codeweavers.com>
Mon, 15 Mar 2010 22:39:15 +0000 (23:39 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Tue, 16 Mar 2010 10:48:22 +0000 (11:48 +0100)
dlls/oleaut32/tests/typelib.c
dlls/oleaut32/typelib2.c

index 0b26e6c8896826dc2acb2bd1f4a924ac50eebaf8..b31466e0f56dcfd8bce0d2b9c810e1a34340b60b 100644 (file)
@@ -1425,19 +1425,19 @@ static void test_CreateTypeLib(void) {
 
     hres = ICreateTypeLib2_SaveAllChanges(createtl);
     ok(hres == S_OK, "got %08x\n", hres);
-    ICreateTypeLib2_Release(createtl);
 
     hres = LoadTypeLibEx(filenameW, REGKIND_NONE, &tl);
     ok(hres == S_OK, "got %08x\n", hres);
 
-    ITypeInfo_Release(interface2);
-    ITypeInfo_Release(interface1);
-    ITypeInfo_Release(dual);
-    ITypeInfo_Release(dispatch);
-    ITypeInfo_Release(unknown);
+    ok(ITypeInfo_Release(interface2)==0, "Object should be freed\n");
+    ok(ITypeInfo_Release(interface1)==0, "Object should be freed\n");
+    ok(ITypeInfo_Release(dual)==0, "Object should be freed\n");
+    ok(ICreateTypeLib2_Release(createtl)==0, "Object should be freed\n");
+    ok(ITypeInfo_Release(dispatch)==0, "Object should be freed\n");
+    ok(ITypeInfo_Release(unknown)==0, "Object should be freed\n");
 
-    ITypeLib_Release(tl);
-    ITypeLib_Release(stdole);
+    ok(ITypeLib_Release(tl)==0, "Object should be freed\n");
+    ok(ITypeLib_Release(stdole)==0, "Object should be freed\n");
 
     DeleteFileA(filename);
 }
index 08f650cca030caec50fc028e29dedc18dee15545..60b9f73f52014d4daf20d45c6490aee5e12157ef 100644 (file)
@@ -1315,7 +1315,7 @@ static HRESULT WINAPI ICreateTypeInfo2_fnQueryInterface(
 
     if(*ppvObject)
     {
-        ICreateTypeLib2_AddRef(iface);
+        ICreateTypeInfo2_AddRef(iface);
         TRACE("-- Interface: (%p)->(%p)\n",ppvObject,*ppvObject);
         return S_OK;
     }
@@ -1583,8 +1583,10 @@ static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
 
         /* Allocate container GUID */
         hres = ITypeLib_GetLibAttr(container, &tlibattr);
-        if(FAILED(hres))
+        if(FAILED(hres)) {
+            ITypeLib_Release(container);
             return hres;
+        }
 
         guid.guid = tlibattr->guid;
         guid.hreftype = This->typelib->typelib_guids*12+2;
@@ -1593,6 +1595,7 @@ static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
         guid_offset = ctl2_alloc_guid(This->typelib, &guid);
         if(guid_offset == -1) {
             ITypeLib_ReleaseTLibAttr(container, tlibattr);
+            ITypeLib_Release(container);
             return E_OUTOFMEMORY;
         }
 
@@ -1613,6 +1616,7 @@ static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
             || (p=strrchrW(name, '\\'))==NULL) {
             ERR("Error guessing typelib filename\n");
             ITypeLib_ReleaseTLibAttr(container, tlibattr);
+            ITypeLib_Release(container);
             return E_NOTIMPL;
         }
         memmove(name, p+1, strlenW(p)*sizeof(WCHAR));
@@ -1622,13 +1626,17 @@ static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
                 tlibattr->lcid, tlibattr->wMajorVerNum, tlibattr->wMinorVerNum, name);
         ITypeLib_ReleaseTLibAttr(container, tlibattr);
 
-        if(import_offset == -1)
+        if(import_offset == -1) {
+            ITypeLib_Release(container);
             return E_OUTOFMEMORY;
+        }
 
         /* Allocate referenced guid */
         hres = ITypeInfo_GetTypeAttr(pTInfo, &typeattr);
-        if(FAILED(hres))
+        if(FAILED(hres)) {
+            ITypeLib_Release(container);
             return hres;
+        }
 
         guid.guid = typeattr->guid;
         guid.hreftype = This->typelib->typeinfo_guids*12+1;
@@ -1636,8 +1644,10 @@ static HRESULT WINAPI ICreateTypeInfo2_fnAddRefTypeInfo(
         ITypeInfo_ReleaseTypeAttr(pTInfo, typeattr);
 
         guid_offset = ctl2_alloc_guid(This->typelib, &guid);
-        if(guid_offset == -1)
+        if(guid_offset == -1) {
+            ITypeLib_Release(container);
             return E_OUTOFMEMORY;
+        }
 
         check_guid = (MSFT_GuidEntry*)&This->typelib->typelib_segment_data[MSFT_SEG_GUID][guid_offset];
         if(check_guid->hreftype == guid.hreftype)
@@ -2390,15 +2400,17 @@ static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
             return hres;
 
         hres = ITypeInfo_GetRefTypeInfo(next, hreftype, &cur);
+        ITypeInfo_Release(next);
         if(FAILED(hres))
             return hres;
 
-        ITypeInfo_Release(next);
 
         while(1) {
             hres = ITypeInfo_GetTypeAttr(cur, &typeattr);
-            if(FAILED(hres))
+            if(FAILED(hres)) {
+                ITypeInfo_Release(cur);
                 return hres;
+            }
 
             if(!memcmp(&typeattr->guid, &IID_IDispatch, sizeof(IDispatch)))
                 This->typeinfo->flags |= TYPEFLAG_FDISPATCHABLE;
@@ -2409,16 +2421,21 @@ static HRESULT WINAPI ICreateTypeInfo2_fnLayOut(
             hres = ITypeInfo_GetRefTypeOfImplType(cur, 0, &hreftype);
             if(hres == TYPE_E_ELEMENTNOTFOUND)
                 break;
-            if(FAILED(hres))
+            if(FAILED(hres)) {
+                ITypeInfo_Release(cur);
                 return hres;
+            }
 
             hres = ITypeInfo_GetRefTypeInfo(cur, hreftype, &next);
-            if(FAILED(hres))
+            if(FAILED(hres)) {
+                ITypeInfo_Release(cur);
                 return hres;
+            }
 
             ITypeInfo_Release(cur);
             cur = next;
         }
+        ITypeInfo_Release(cur);
     }
 
     This->typeinfo->cbSizeVft = (This->typeinfo->datatype2>>16) * 4;
@@ -3102,6 +3119,7 @@ static HRESULT WINAPI ITypeInfo2_fnGetRefTypeInfo(
 
     if(hRefType==-2 && This->dual) {
         *ppTInfo = (ITypeInfo*)&This->dual->lpVtblTypeInfo2;
+        ITypeInfo_AddRef(*ppTInfo);
         return S_OK;
     }
 
@@ -3207,7 +3225,7 @@ static HRESULT WINAPI ITypeInfo2_fnGetContainingTypeLib(
     TRACE("(%p,%p,%p)\n", iface, ppTLib, pIndex);
     
     *ppTLib = (ITypeLib *)&This->typelib->lpVtblTypeLib2;
-    This->typelib->ref++;
+    ICreateTypeLib_AddRef((ICreateTypeLib*)This->typelib);
     *pIndex = This->typeinfo->typekind >> 16;
 
     return S_OK;
@@ -3656,7 +3674,7 @@ static ICreateTypeInfo2 *ICreateTypeInfo2_Constructor(ICreateTypeLib2Impl *typel
     pCreateTypeInfo2Impl->ref = 1;
 
     pCreateTypeInfo2Impl->typelib = typelib;
-    typelib->ref++;
+    ICreateTypeLib_AddRef((ICreateTypeLib*)typelib);
 
     nameoffset = ctl2_alloc_name(typelib, szName);
     typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);