From 3bd31cfd1620cbc826c840e857e212fbf4c215a7 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Mon, 26 Feb 2007 12:57:19 +0000 Subject: [PATCH] ole32: The stream returned by StgStreamImpl_Clone should have one reference, so call AddRef before returning. Move the call to StorageBaseImpl_AddStream to StgStreamImpl_Construct to fix StgStreamImpl_Clone, which forgets to call it. Add tests for OLE structured storage tests for IStream::Clone. --- dlls/ole32/stg_stream.c | 5 +++++ dlls/ole32/storage32.c | 15 +-------------- dlls/ole32/storage32.h | 1 + dlls/ole32/tests/storage32.c | 6 ++++++ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/dlls/ole32/stg_stream.c b/dlls/ole32/stg_stream.c index 63bdaadd1b9..6f2ec9a7a62 100644 --- a/dlls/ole32/stg_stream.c +++ b/dlls/ole32/stg_stream.c @@ -880,6 +880,8 @@ static HRESULT WINAPI StgStreamImpl_Clone( return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */ *ppstm = (IStream*) new_stream; + IStream_AddRef(*ppstm); + seek_pos.QuadPart = This->currentPosition.QuadPart; hres=StgStreamImpl_Seek (*ppstm, seek_pos, STREAM_SEEK_SET, NULL); @@ -974,6 +976,9 @@ StgStreamImpl* StgStreamImpl_Construct( * this stream are large or small. */ StgStreamImpl_OpenBlockChain(newStream); + + /* add us to the storage's list of active streams */ + StorageBaseImpl_AddStream(parentStorage, newStream); } return newStream; diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c index c575ce5a396..dc2db11474b 100644 --- a/dlls/ole32/storage32.c +++ b/dlls/ole32/storage32.c @@ -93,8 +93,6 @@ static void StorageImpl_SetNextBlockInChain(StorageImpl* This, ULONG blockIndex, static HRESULT StorageImpl_LoadFileHeader(StorageImpl* This); static void StorageImpl_SaveFileHeader(StorageImpl* This); -static void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm); - static void Storage32Impl_AddBlockDepot(StorageImpl* This, ULONG blockIndex); static ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This); static ULONG Storage32Impl_GetNextExtendedBlock(StorageImpl* This, ULONG blockIndex); @@ -468,12 +466,6 @@ static HRESULT WINAPI StorageBaseImpl_OpenStream( */ IStream_AddRef(*ppstm); - /* - * add us to the storage's list of active streams - */ - - StorageBaseImpl_AddStream(This,newStream); - res = S_OK; goto end; } @@ -1063,11 +1055,6 @@ static HRESULT WINAPI StorageBaseImpl_CreateStream( * the reference. */ IStream_AddRef(*ppstm); - - /* add us to the storage's list of active streams - */ - StorageBaseImpl_AddStream(This,newStream); - } else { @@ -1895,7 +1882,7 @@ static HRESULT WINAPI StorageImpl_Stat( IStorage* iface, * Internal stream list handlers */ -static void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm) +void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm) { TRACE("Stream added (stg=%p strm=%p)\n", stg, strm); list_add_tail(&stg->strmHead,&strm->StrmListEntry); diff --git a/dlls/ole32/storage32.h b/dlls/ole32/storage32.h index 5f2aea841c9..569cb36e035 100644 --- a/dlls/ole32/storage32.h +++ b/dlls/ole32/storage32.h @@ -257,6 +257,7 @@ struct StorageBaseImpl * StorageBaseImpl stream list handlers */ +void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm); void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm); /**************************************************************************** diff --git a/dlls/ole32/tests/storage32.c b/dlls/ole32/tests/storage32.c index 9a90ad3ddea..710aa450459 100644 --- a/dlls/ole32/tests/storage32.c +++ b/dlls/ole32/tests/storage32.c @@ -232,6 +232,7 @@ static void test_storage_stream(void) IStorage *stg = NULL; HRESULT r; IStream *stm = NULL; + IStream *stm2 = NULL; ULONG count = 0; LARGE_INTEGER pos; ULARGE_INTEGER p; @@ -281,6 +282,9 @@ static void test_storage_stream(void) r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm ); ok(r==S_OK, "IStorage->CreateStream failed\n"); + r = IStream_Clone(stm, &stm2); + ok(r==S_OK, "failed to clone stream\n"); + r = IStream_Write(stm, NULL, 0, NULL ); ok(r==STG_E_INVALIDPOINTER, "IStream->Write wrong error\n"); r = IStream_Write(stm, "Hello\n", 0, NULL ); @@ -317,6 +321,8 @@ static void test_storage_stream(void) ok(count == 0, "read bytes from empty stream\n"); /* wrap up */ + r = IStream_Release(stm2); + ok(r == 0, "wrong ref count\n"); r = IStream_Release(stm); ok(r == 0, "wrong ref count\n"); r = IStorage_Release(stg);