[PATCH 4/4] Don't leak document and stread on next IXMLDocument::Load()

Nikolay Sivov bunglehead at gmail.com
Tue Jan 12 08:37:03 CST 2010


---
 dlls/msxml3/tests/xmldoc.c |    8 ++++++++
 dlls/msxml3/xmldoc.c       |    6 ++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/dlls/msxml3/tests/xmldoc.c b/dlls/msxml3/tests/xmldoc.c
index 2dbb2f1..c21a19e 100644
--- a/dlls/msxml3/tests/xmldoc.c
+++ b/dlls/msxml3/tests/xmldoc.c
@@ -431,6 +431,14 @@ static void test_persiststreaminit(void)
     hr = IPersistStreamInit_IsDirty(psi);
     todo_wine ok(hr == S_FALSE, "Expected S_OK, got %08x\n", hr);
 
+    create_stream_on_file(&stream, path);
+    hr = IPersistStreamInit_Load(psi, stream);
+    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
+    IStream_Release(stream);
+
+    hr = IPersistStreamInit_IsDirty(psi);
+    todo_wine ok(hr == S_FALSE, "Expected S_OK, got %08x\n", hr);
+
     /* reset internal stream */
     hr = IPersistStreamInit_InitNew(psi);
     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
diff --git a/dlls/msxml3/xmldoc.c b/dlls/msxml3/xmldoc.c
index 2ca874b..cf39cc5 100644
--- a/dlls/msxml3/xmldoc.c
+++ b/dlls/msxml3/xmldoc.c
@@ -616,6 +616,8 @@ static HRESULT WINAPI xmldoc_IPersistStreamInit_Load(
     if (!pStm)
         return E_INVALIDARG;
 
+    /* release previously allocated stream */
+    if (This->stream) IStream_Release(This->stream);
     hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
     if (FAILED(hr))
         return hr;
@@ -639,7 +641,10 @@ static HRESULT WINAPI xmldoc_IPersistStreamInit_Load(
     len = GlobalSize(hglobal);
     ptr = GlobalLock(hglobal);
     if (len != 0)
+    {
+        xmlFreeDoc(This->xmldoc);
         This->xmldoc = parse_xml(ptr, len);
+    }
     GlobalUnlock(hglobal);
 
     if (!This->xmldoc)
@@ -648,6 +653,7 @@ static HRESULT WINAPI xmldoc_IPersistStreamInit_Load(
         return E_FAIL;
     }
 
+    if (This->root) IXMLElement_Release(This->root);
     xmlnode = xmlDocGetRootElement(This->xmldoc);
     return XMLElement_create((IUnknown *)This, xmlnode, (LPVOID *)&This->root);
 }
-- 
1.5.6.5


--=-EyJ/CoG7eIAl1m9NGPBO--




More information about the wine-patches mailing list