Apache OpenOffice (AOO) Bugzilla – Issue 11704
storeToUrl(L"private:stream") holds on to stream
Last modified: 2013-02-24 21:07:45 UTC
We have a requirement to store documents to memory instead of to a file. For this purpose we are passing in a custom memory stream object to the storeToURL () function as follows: Sequence<::com::sun::star::beans::PropertyValue> aArgs(1); ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray(); pArg[0].Name = L"OutputStream"; pArg[0].Value <<= CreateMemStream()->getOutputStream(); // XStream object returns XOutputStream xStorable->storeToURL(L"private:stream", aArgs); The ref count on the stream object remains at 2. This seems to make OO.o unstable and causes it to crash later on (not the case with storing to a file). This was originally posted to 'dev@api.openoffice.org' with one response from Michael Hoennig [mi@sun.com]: "Does it still crash when the stream is closed after storeToUrl() using XOutputStream::closeOutput()? But I think it should not. Would you file an issue about this in IssueZilla?" Please note, Michael Hoennig's response did not resolve this issue because OO.o never calls XOutputStream::closeOutput()
implementation issue
Target adjusted
I'm not sure where the superfluous reference is kept, perhaps in SfxMedium?
I will investigate the refcounting problem. As for XOutputStream::closeOutput(), the caller of StoreToURL should call this method after saving to the stream.
A temporary ItemSet created by SfxBaseModel was not deleted.
The following script can be used for testing but the file pathes should be adjusted. The result of the macro is the NewFile opened for editing. Before the bug was fixed this file could not be opened for editing since the stream that holt the lock was not released. REM ***** BASIC ***** Sub Main REM PLEASE ADJUST THE PATHES ExistingFile = "file:///d:/OLE_TEST/test.sxw" NewFile = "file:///d:/temp.sxw" Dim aPropArray(0) as Object aPropArray(0) = CreateUnoStruct("com.sun.star.beans.PropertyValue") aPropArray(0).Name = "MacroExecutionMode" aPropArray(0).Value = 0 oDoc = StarDesktop.loadComponentFromURL( ExistingFile, "_blank", 0, aPropArray() ) oFileAcc = createUnoService ( "com.sun.star.ucb.SimpleFileAccess" ) xStream = oFileAcc.openFileWrite ( NewFile ) Dim aPArray(1) as Object aPArray(0) = CreateUnoStruct("com.sun.star.beans.PropertyValue") aPArray(0).Name = "InteractionHandler" aPArray(0).Value = createUnoService( "com.sun.star.task.InteractionHandler" ) aPArray(1) = CreateUnoStruct("com.sun.star.beans.PropertyValue") aPArray(1).Name = "OutputStream" aPArray(1).Value = xStream oDoc.storeToURL( "private:stream", aPArray() ) xStream.closeOutput() oDoc.close( true ) oDocNew = StarDesktop.loadComponentFromURL( NewFile, "_blank", 0, aPropArray() ) End Sub
Ok in m12s1