From abdebcdbbe61cfaf7c9198f279637ec69daa63d1 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Fri, 25 Sep 2009 16:27:49 +0200 Subject: [PATCH] ole32/storage32: Fix for reference counters in nested storage. --- dlls/ole32/storage32.c | 4 +--- dlls/ole32/tests/storage32.c | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c index 6e3e1e1d978..90823347039 100644 --- a/dlls/ole32/storage32.c +++ b/dlls/ole32/storage32.c @@ -3713,7 +3713,6 @@ static void StorageInternalImpl_Destroy( StorageBaseImpl *iface) { StorageInternalImpl* This = (StorageInternalImpl*) iface; - StorageBaseImpl_Release((IStorage*)This->base.ancestorStorage); HeapFree(GetProcessHeap(), 0, This); } @@ -4312,10 +4311,9 @@ static StorageInternalImpl* StorageInternalImpl_Construct( newStorage->base.openFlags = (openFlags & ~STGM_CREATE); /* - * Keep the ancestor storage pointer and nail a reference to it. + * Keep the ancestor storage pointer but do not nail a reference to it. */ newStorage->base.ancestorStorage = ancestorStorage; - StorageBaseImpl_AddRef((IStorage*)(newStorage->base.ancestorStorage)); /* * Keep the index of the root property set for this storage, diff --git a/dlls/ole32/tests/storage32.c b/dlls/ole32/tests/storage32.c index fec854e5c28..620e6cba14c 100644 --- a/dlls/ole32/tests/storage32.c +++ b/dlls/ole32/tests/storage32.c @@ -1470,6 +1470,45 @@ static void test_fmtusertypestg(void) } } +static void test_references(void) +{ + IStorage *stg,*stg2; + HRESULT hr; + unsigned c1,c2; + static const WCHAR StorName[] = { 'D','a','t','a','S','p','a','c','e','I','n','f','o',0 }; + + DeleteFileA(filenameA); + + hr = StgCreateDocfile( filename, STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_READWRITE |STGM_TRANSACTED, 0, &stg); + ok(hr==S_OK, "StgCreateDocfile failed\n"); + + if (SUCCEEDED(hr)) + { + IStorage_Release(stg); + + hr = StgOpenStorage( filename, NULL, STGM_TRANSACTED | STGM_SHARE_EXCLUSIVE | STGM_READWRITE, NULL, 0, &stg); + ok(hr==S_OK, "StgOpenStorage failed (result=%x)\n",hr); + + if (SUCCEEDED(hr)) + { + hr = IStorage_CreateStorage(stg,StorName,STGM_READWRITE | STGM_SHARE_EXCLUSIVE,0,0,&stg2); + ok(hr == S_OK, "IStorage_CreateStorage failed (result=%x)\n",hr); + + if (SUCCEEDED(hr)) + { + c1 = IStorage_AddRef(stg); + ok(c1 == 2, "creating internal storage added references to ancestor\n"); + c1 = IStorage_AddRef(stg); + IStorage_Release(stg2); + c2 = IStorage_AddRef(stg) - 1; + ok(c1 == c2, "releasing internal storage removed references to ancestor\n"); + } + c1 = IStorage_Release(stg); + while ( c1 ) c1 = IStorage_Release(stg); + } + } +} + START_TEST(storage32) { CHAR temp[MAX_PATH]; @@ -1497,4 +1536,5 @@ START_TEST(storage32) test_readonly(); test_simple(); test_fmtusertypestg(); + test_references(); }