From bf9f8da333b3f278d0e031f10fb1299c9f1ee9ad Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 19 Aug 2004 20:29:16 +0000 Subject: [PATCH] Ref counting fixes. --- dlls/oleaut32/tests/.cvsignore | 1 + dlls/oleaut32/tests/Makefile.in | 1 + dlls/oleaut32/tests/typelib.c | 66 +++++++++++++++++++++++++++++++++++++++++ dlls/oleaut32/typelib.c | 11 ++++--- 4 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 dlls/oleaut32/tests/typelib.c diff --git a/dlls/oleaut32/tests/.cvsignore b/dlls/oleaut32/tests/.cvsignore index 42059403f6f..4c11397585a 100644 --- a/dlls/oleaut32/tests/.cvsignore +++ b/dlls/oleaut32/tests/.cvsignore @@ -2,5 +2,6 @@ Makefile olefont.ok safearray.ok testlist.c +typelib.ok vartest.ok vartype.ok diff --git a/dlls/oleaut32/tests/Makefile.in b/dlls/oleaut32/tests/Makefile.in index 766ac44b392..48e7a832ca0 100644 --- a/dlls/oleaut32/tests/Makefile.in +++ b/dlls/oleaut32/tests/Makefile.in @@ -9,6 +9,7 @@ EXTRALIBS = -luuid CTESTS = \ olefont.c \ safearray.c \ + typelib.c \ vartest.c \ vartype.c diff --git a/dlls/oleaut32/tests/typelib.c b/dlls/oleaut32/tests/typelib.c new file mode 100644 index 00000000000..6ecf5bd6e96 --- /dev/null +++ b/dlls/oleaut32/tests/typelib.c @@ -0,0 +1,66 @@ +/* + * ITypeLib and ITypeInfo test + * + * Copyright 2004 Jacek Caban + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define COBJMACROS + +#include +#include + +#include "windef.h" +#include "winbase.h" +#include "oleauto.h" + +void ref_count_test(LPCWSTR type_lib) +{ + ITypeLib *iface; + ITypeInfo *iti1, *iti2; + HRESULT hRes; + int ref_count; + + trace("Loading type library\n"); + hRes = LoadTypeLib(type_lib, &iface); + ok(hRes == S_OK, "Could not load type library\n"); + if(hRes != S_OK) + return; + + hRes = ITypeLib_GetTypeInfo(iface, 1, &iti1); + ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n"); + ok(ref_count=ITypeLib_Release(iface) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n"); + if(!ref_count) + return; + + hRes = ITypeLib_GetTypeInfo(iface, 1, &iti2); + ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n"); + ok(iti1 == iti2, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n"); + + ITypeLib_AddRef(iface); + ITypeInfo_Release(iti2); + ITypeInfo_Release(iti1); + ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n"); +} + +START_TEST(typelib) +{ + static const WCHAR type_lib_olepro32[] = {'o','l','e','p','r','o','3','2','.','d','l','l',0}; + static const WCHAR type_lib_stdole32[] = {'s','t','d','o','l','e','3','2','.','t','l','b',0}; + + ref_count_test(type_lib_olepro32); + ref_count_test(type_lib_stdole32); +} diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c index 27540166dfe..41659dba0fd 100644 --- a/dlls/oleaut32/typelib.c +++ b/dlls/oleaut32/typelib.c @@ -2460,7 +2460,6 @@ static ITypeLib2* ITypeLib2_Constructor_MSFT(LPVOID pLib, DWORD dwTLBLength) { *ppTI = MSFT_DoTypeInfo(&cx, i, pTypeLibImpl); - ITypeInfo_AddRef((ITypeInfo*) *ppTI); ppTI = &((*ppTI)->next); (pTypeLibImpl->TypeInfoCount)++; } @@ -4079,6 +4078,7 @@ static ULONG WINAPI ITypeInfo_fnAddRef( ITypeInfo2 *iface) ICOM_THIS( ITypeInfoImpl, iface); ++(This->ref); + ITypeLib2_AddRef((ITypeLib2*)This->pTypeLib); TRACE("(%p)->ref is %u\n",This, This->ref); return This->ref; @@ -4086,7 +4086,7 @@ static ULONG WINAPI ITypeInfo_fnAddRef( ITypeInfo2 *iface) /* ITypeInfo::Release */ -static ULONG WINAPI ITypeInfo_fnRelease( ITypeInfo2 *iface) +static ULONG WINAPI ITypeInfo_fnRelease(ITypeInfo2 *iface) { ICOM_THIS( ITypeInfoImpl, iface); @@ -4094,8 +4094,11 @@ static ULONG WINAPI ITypeInfo_fnRelease( ITypeInfo2 *iface) TRACE("(%p)->(%u)\n",This, This->ref); - if (!This->ref) - { + if (This->ref) { + /* We don't release ITypeLib when ref=0 becouse + it means that funtion is called by ITypeLi2_Release */ + ITypeLib2_Release((ITypeLib2*)This->pTypeLib); + } else { FIXME("destroy child objects\n"); TRACE("destroying ITypeInfo(%p)\n",This); -- 2.11.4.GIT