msxml3: Fix handling of NULL object site (Coverity)

Nikolay Sivov nsivov at codeweavers.com
Wed Nov 28 06:00:02 CST 2012


CID 215523
-------------- next part --------------
>From 159c40c13669b4d8c6fd25f9641ea2a84e0594b0 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov at codeweavers.com>
Date: Wed, 28 Nov 2012 13:11:19 -0500
Subject: [PATCH 5/7] Fix handling of NULL object site (Coverity)

---
 dlls/msxml3/httprequest.c  |   33 ++++++++++++++++++---------------
 dlls/msxml3/tests/domdoc.c |    3 +++
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/dlls/msxml3/httprequest.c b/dlls/msxml3/httprequest.c
index 2600ffe..9d93cca 100644
--- a/dlls/msxml3/httprequest.c
+++ b/dlls/msxml3/httprequest.c
@@ -1444,34 +1444,37 @@ static HRESULT WINAPI httprequest_ObjectWithSite_GetSite( IObjectWithSite *iface
 static HRESULT WINAPI httprequest_ObjectWithSite_SetSite( IObjectWithSite *iface, IUnknown *punk )
 {
     httprequest *This = impl_from_IObjectWithSite(iface);
-    IServiceProvider *provider;
-    HRESULT hr;
-
-    TRACE("(%p)->(%p)\n", iface, punk);
 
-    if (punk)
-        IUnknown_AddRef( punk );
+    TRACE("(%p)->(%p)\n", This, punk);
 
     if(This->site)
         IUnknown_Release( This->site );
 
+    SysFreeString(This->siteurl);
+    This->siteurl = NULL;
     This->site = punk;
 
-    hr = IUnknown_QueryInterface(This->site, &IID_IServiceProvider, (void**)&provider);
-    if (hr == S_OK)
+    if (punk)
     {
-        IHTMLDocument2 *doc;
+        IServiceProvider *provider;
+        HRESULT hr;
+
+        IUnknown_AddRef( punk );
 
-        hr = IServiceProvider_QueryService(provider, &SID_SContainerDispatch, &IID_IHTMLDocument2, (void**)&doc);
+        hr = IUnknown_QueryInterface(This->site, &IID_IServiceProvider, (void**)&provider);
         if (hr == S_OK)
         {
-            SysFreeString(This->siteurl);
+            IHTMLDocument2 *doc;
 
-            hr = IHTMLDocument2_get_URL(doc, &This->siteurl);
-            IHTMLDocument2_Release(doc);
-            TRACE("host url %s, 0x%08x\n", debugstr_w(This->siteurl), hr);
+            hr = IServiceProvider_QueryService(provider, &SID_SContainerDispatch, &IID_IHTMLDocument2, (void**)&doc);
+            if (hr == S_OK)
+            {
+                hr = IHTMLDocument2_get_URL(doc, &This->siteurl);
+                IHTMLDocument2_Release(doc);
+                TRACE("host url %s, 0x%08x\n", debugstr_w(This->siteurl), hr);
+            }
+            IServiceProvider_Release(provider);
         }
-        IServiceProvider_Release(provider);
     }
 
     return S_OK;
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index 3a62c95..d75bb5f 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -5213,6 +5213,9 @@ todo_wine {
     EXPECT_REF(obj_site, 1);
 }
 
+    hr = IObjectWithSite_SetSite(obj_site, NULL);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
     IObjectWithSite_AddRef(obj_site);
 todo_wine {
     EXPECT_REF(obj_site, 2);
-- 
1.7.10.4




More information about the wine-patches mailing list