Commit 3bd31cfd authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

ole32: The stream returned by StgStreamImpl_Clone should have one reference, so…

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.
parent 85aefa35
...@@ -880,6 +880,8 @@ static HRESULT WINAPI StgStreamImpl_Clone( ...@@ -880,6 +880,8 @@ static HRESULT WINAPI StgStreamImpl_Clone(
return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */ return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */
*ppstm = (IStream*) new_stream; *ppstm = (IStream*) new_stream;
IStream_AddRef(*ppstm);
seek_pos.QuadPart = This->currentPosition.QuadPart; seek_pos.QuadPart = This->currentPosition.QuadPart;
hres=StgStreamImpl_Seek (*ppstm, seek_pos, STREAM_SEEK_SET, NULL); hres=StgStreamImpl_Seek (*ppstm, seek_pos, STREAM_SEEK_SET, NULL);
...@@ -974,6 +976,9 @@ StgStreamImpl* StgStreamImpl_Construct( ...@@ -974,6 +976,9 @@ StgStreamImpl* StgStreamImpl_Construct(
* this stream are large or small. * this stream are large or small.
*/ */
StgStreamImpl_OpenBlockChain(newStream); StgStreamImpl_OpenBlockChain(newStream);
/* add us to the storage's list of active streams */
StorageBaseImpl_AddStream(parentStorage, newStream);
} }
return newStream; return newStream;
......
...@@ -93,8 +93,6 @@ static void StorageImpl_SetNextBlockInChain(StorageImpl* This, ULONG blockIndex, ...@@ -93,8 +93,6 @@ static void StorageImpl_SetNextBlockInChain(StorageImpl* This, ULONG blockIndex,
static HRESULT StorageImpl_LoadFileHeader(StorageImpl* This); static HRESULT StorageImpl_LoadFileHeader(StorageImpl* This);
static void StorageImpl_SaveFileHeader(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 void Storage32Impl_AddBlockDepot(StorageImpl* This, ULONG blockIndex);
static ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This); static ULONG Storage32Impl_AddExtBlockDepot(StorageImpl* This);
static ULONG Storage32Impl_GetNextExtendedBlock(StorageImpl* This, ULONG blockIndex); static ULONG Storage32Impl_GetNextExtendedBlock(StorageImpl* This, ULONG blockIndex);
...@@ -468,12 +466,6 @@ static HRESULT WINAPI StorageBaseImpl_OpenStream( ...@@ -468,12 +466,6 @@ static HRESULT WINAPI StorageBaseImpl_OpenStream(
*/ */
IStream_AddRef(*ppstm); IStream_AddRef(*ppstm);
/*
* add us to the storage's list of active streams
*/
StorageBaseImpl_AddStream(This,newStream);
res = S_OK; res = S_OK;
goto end; goto end;
} }
...@@ -1063,11 +1055,6 @@ static HRESULT WINAPI StorageBaseImpl_CreateStream( ...@@ -1063,11 +1055,6 @@ static HRESULT WINAPI StorageBaseImpl_CreateStream(
* the reference. * the reference.
*/ */
IStream_AddRef(*ppstm); IStream_AddRef(*ppstm);
/* add us to the storage's list of active streams
*/
StorageBaseImpl_AddStream(This,newStream);
} }
else else
{ {
...@@ -1895,7 +1882,7 @@ static HRESULT WINAPI StorageImpl_Stat( IStorage* iface, ...@@ -1895,7 +1882,7 @@ static HRESULT WINAPI StorageImpl_Stat( IStorage* iface,
* Internal stream list handlers * 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); TRACE("Stream added (stg=%p strm=%p)\n", stg, strm);
list_add_tail(&stg->strmHead,&strm->StrmListEntry); list_add_tail(&stg->strmHead,&strm->StrmListEntry);
......
...@@ -257,6 +257,7 @@ struct StorageBaseImpl ...@@ -257,6 +257,7 @@ struct StorageBaseImpl
* StorageBaseImpl stream list handlers * StorageBaseImpl stream list handlers
*/ */
void StorageBaseImpl_AddStream(StorageBaseImpl * stg, StgStreamImpl * strm);
void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm); void StorageBaseImpl_RemoveStream(StorageBaseImpl * stg, StgStreamImpl * strm);
/**************************************************************************** /****************************************************************************
......
...@@ -232,6 +232,7 @@ static void test_storage_stream(void) ...@@ -232,6 +232,7 @@ static void test_storage_stream(void)
IStorage *stg = NULL; IStorage *stg = NULL;
HRESULT r; HRESULT r;
IStream *stm = NULL; IStream *stm = NULL;
IStream *stm2 = NULL;
ULONG count = 0; ULONG count = 0;
LARGE_INTEGER pos; LARGE_INTEGER pos;
ULARGE_INTEGER p; ULARGE_INTEGER p;
...@@ -281,6 +282,9 @@ static void test_storage_stream(void) ...@@ -281,6 +282,9 @@ static void test_storage_stream(void)
r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm ); r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
ok(r==S_OK, "IStorage->CreateStream failed\n"); 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 ); r = IStream_Write(stm, NULL, 0, NULL );
ok(r==STG_E_INVALIDPOINTER, "IStream->Write wrong error\n"); ok(r==STG_E_INVALIDPOINTER, "IStream->Write wrong error\n");
r = IStream_Write(stm, "Hello\n", 0, NULL ); r = IStream_Write(stm, "Hello\n", 0, NULL );
...@@ -317,6 +321,8 @@ static void test_storage_stream(void) ...@@ -317,6 +321,8 @@ static void test_storage_stream(void)
ok(count == 0, "read bytes from empty stream\n"); ok(count == 0, "read bytes from empty stream\n");
/* wrap up */ /* wrap up */
r = IStream_Release(stm2);
ok(r == 0, "wrong ref count\n");
r = IStream_Release(stm); r = IStream_Release(stm);
ok(r == 0, "wrong ref count\n"); ok(r == 0, "wrong ref count\n");
r = IStorage_Release(stg); r = IStorage_Release(stg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment