hlink: Use CoTaskMemAlloc when returning memory to a caller.

This commit is contained in:
Mike McCormack 2006-08-02 02:15:30 +09:00 committed by Alexandre Julliard
parent dc3d475147
commit af29c05a05
1 changed files with 19 additions and 40 deletions

View File

@ -80,6 +80,18 @@ static inline LPWSTR strdupW( LPCWSTR str )
return r; 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) static inline void __GetMoniker(HlinkImpl* This, IMoniker** moniker)
{ {
*moniker = NULL; *moniker = NULL;
@ -281,13 +293,9 @@ static HRESULT WINAPI IHlink_fnGetStringReference (IHlink* iface,
if (ppwzTarget) if (ppwzTarget)
{ {
if (This->Target) *ppwzTarget = co_strdupW( This->Target );
{
*ppwzTarget = HeapAlloc(GetProcessHeap(), 0, if (!This->Target)
(lstrlenW(This->Target)+1) * sizeof(WCHAR));
lstrcpyW(*ppwzTarget, This->Target);
}
else
{ {
IMoniker* mon; IMoniker* mon;
__GetMoniker(This, &mon); __GetMoniker(This, &mon);
@ -296,34 +304,16 @@ static HRESULT WINAPI IHlink_fnGetStringReference (IHlink* iface,
IBindCtx *pbc; IBindCtx *pbc;
CreateBindCtx( 0, &pbc); CreateBindCtx( 0, &pbc);
IMoniker_GetDisplayName(mon, pbc, NULL, &This->Target); IMoniker_GetDisplayName(mon, pbc, NULL, ppwzTarget);
IBindCtx_Release(pbc); IBindCtx_Release(pbc);
*ppwzTarget = HeapAlloc(GetProcessHeap(), 0,
(lstrlenW(This->Target)+1) * sizeof(WCHAR));
lstrcpyW(*ppwzTarget, This->Target);
IMoniker_Release(mon); IMoniker_Release(mon);
} }
else else
{
FIXME("Unhandled case, no set Target and no moniker\n"); FIXME("Unhandled case, no set Target and no moniker\n");
*ppwzTarget = NULL;
}
} }
} }
if (ppwzLocation) if (ppwzLocation)
{ *ppwzLocation = co_strdupW( This->Location );
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;
}
}
TRACE("(Target: %s Location: %s)\n", TRACE("(Target: %s Location: %s)\n",
(ppwzTarget)?debugstr_w(*ppwzTarget):"<NULL>", (ppwzTarget)?debugstr_w(*ppwzTarget):"<NULL>",
@ -355,11 +345,7 @@ static HRESULT WINAPI IHlink_fnGetFriendlyName (IHlink* iface,
/* FIXME: Only using explicitly set and cached friendly names */ /* FIXME: Only using explicitly set and cached friendly names */
if (This->FriendlyName) if (This->FriendlyName)
{ *ppwzFriendlyName = co_strdupW( This->FriendlyName );
*ppwzFriendlyName = HeapAlloc(GetProcessHeap(), 0,
(lstrlenW(This->FriendlyName)+1) * sizeof(WCHAR));
lstrcpyW(*ppwzFriendlyName, This->FriendlyName);
}
else else
{ {
IMoniker *moniker; IMoniker *moniker;
@ -398,14 +384,7 @@ static HRESULT WINAPI IHlink_fnGetTargetFrameName(IHlink* iface,
HlinkImpl *This = (HlinkImpl*)iface; HlinkImpl *This = (HlinkImpl*)iface;
TRACE("(%p)->(%p)\n", This, ppwzTargetFrameName); TRACE("(%p)->(%p)\n", This, ppwzTargetFrameName);
if (This->TargetFrameName) *ppwzTargetFrameName = co_strdupW( This->TargetFrameName );
{
*ppwzTargetFrameName = HeapAlloc(GetProcessHeap(), 0,
(lstrlenW(This->TargetFrameName)+1) * sizeof(WCHAR));
lstrcpyW(*ppwzTargetFrameName, This->TargetFrameName);
}
else
*ppwzTargetFrameName = NULL;
return S_OK; return S_OK;
} }