Mike McCormack : hlink: Use CoTaskMemAlloc when returning memory to a caller.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Aug 1 04:57:37 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: af29c05a059c3b215430a2f757ac26f952b601b3
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=af29c05a059c3b215430a2f757ac26f952b601b3

Author: Mike McCormack <mike at codeweavers.com>
Date:   Wed Aug  2 02:15:30 2006 +0900

hlink: Use CoTaskMemAlloc when returning memory to a caller.

---

 dlls/hlink/link.c |   59 +++++++++++++++++------------------------------------
 1 files changed, 19 insertions(+), 40 deletions(-)

diff --git a/dlls/hlink/link.c b/dlls/hlink/link.c
index 72245f0..814785a 100644
--- a/dlls/hlink/link.c
+++ b/dlls/hlink/link.c
@@ -80,6 +80,18 @@ static inline LPWSTR strdupW( LPCWSTR st
     return r;
 }
 
+static inline LPWSTR co_strdupW( LPCWSTR str )
+{
+    LPWSTR r;
+
+    if (!str)
+        return NULL;
+    r = CoTaskMemAlloc((lstrlenW(str)+1) * sizeof (WCHAR));
+    if (r)
+        lstrcpyW(r, str);
+    return r;
+}
+
 static inline void __GetMoniker(HlinkImpl* This, IMoniker** moniker)
 {
     *moniker = NULL;
@@ -281,13 +293,9 @@ static HRESULT WINAPI IHlink_fnGetString
 
     if (ppwzTarget)
     {
-        if (This->Target)
-        {
-            *ppwzTarget = HeapAlloc(GetProcessHeap(), 0,
-                    (lstrlenW(This->Target)+1) * sizeof(WCHAR));
-            lstrcpyW(*ppwzTarget, This->Target);
-        }
-        else
+        *ppwzTarget = co_strdupW( This->Target );
+
+        if (!This->Target)
         {
             IMoniker* mon;
             __GetMoniker(This, &mon);
@@ -296,34 +304,16 @@ static HRESULT WINAPI IHlink_fnGetString
                 IBindCtx *pbc;
 
                 CreateBindCtx( 0, &pbc);
-                IMoniker_GetDisplayName(mon, pbc, NULL, &This->Target);
+                IMoniker_GetDisplayName(mon, pbc, NULL, ppwzTarget);
                 IBindCtx_Release(pbc);
-                *ppwzTarget = HeapAlloc(GetProcessHeap(), 0,
-                        (lstrlenW(This->Target)+1) * sizeof(WCHAR));
-                lstrcpyW(*ppwzTarget, This->Target);
                 IMoniker_Release(mon);
             }
             else
-            {
                 FIXME("Unhandled case, no set Target and no moniker\n");
-                *ppwzTarget = NULL;
-            }
         }
     }
     if (ppwzLocation)
-    {
-        if (This->Location)
-        {
-            *ppwzLocation = HeapAlloc(GetProcessHeap(), 0,
-                    (lstrlenW(This->Location)+1) * sizeof(WCHAR));
-            lstrcpyW(*ppwzLocation, This->Location);
-        }
-        else
-        {
-            FIXME("Unhandled case, no explicitly set Location\n");
-            *ppwzLocation = NULL;
-        }
-    }
+        *ppwzLocation = co_strdupW( This->Location );
 
     TRACE("(Target: %s Location: %s)\n",
             (ppwzTarget)?debugstr_w(*ppwzTarget):"<NULL>",
@@ -355,11 +345,7 @@ static HRESULT WINAPI IHlink_fnGetFriend
     /* FIXME: Only using explicitly set and cached friendly names */
 
     if (This->FriendlyName)
-    {
-        *ppwzFriendlyName = HeapAlloc(GetProcessHeap(), 0,
-                (lstrlenW(This->FriendlyName)+1) * sizeof(WCHAR));
-        lstrcpyW(*ppwzFriendlyName, This->FriendlyName);
-    }
+        *ppwzFriendlyName = co_strdupW( This->FriendlyName );
     else
     {
         IMoniker *moniker;
@@ -398,14 +384,7 @@ static HRESULT WINAPI IHlink_fnGetTarget
     HlinkImpl  *This = (HlinkImpl*)iface;
 
     TRACE("(%p)->(%p)\n", This, ppwzTargetFrameName);
-    if (This->TargetFrameName)
-    {
-        *ppwzTargetFrameName = HeapAlloc(GetProcessHeap(), 0,
-                (lstrlenW(This->TargetFrameName)+1) * sizeof(WCHAR));
-        lstrcpyW(*ppwzTargetFrameName, This->TargetFrameName);
-    }
-    else
-        *ppwzTargetFrameName = NULL;
+    *ppwzTargetFrameName = co_strdupW( This->TargetFrameName );
 
     return S_OK;
 }




More information about the wine-cvs mailing list