Commit 4768ac44 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

ole32: Fix leaks on error paths (Coverity).

parent 43b5f46f
......@@ -935,11 +935,12 @@ static HRESULT WINAPI
FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
{
LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
IBindCtx *pbind;
LPOLESTR pathThis = NULL, pathOther = NULL,*stringTable1,*stringTable2,commonPath = NULL;
IBindCtx *bindctx;
DWORD mkSys;
ULONG nb1,nb2,i,sameIdx;
BOOL machineNameCase = FALSE;
HRESULT ret;
if (ppmkPrefix==NULL)
return E_POINTER;
......@@ -951,81 +952,81 @@ FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** p
/* check if we have the same type of moniker */
IMoniker_IsSystemMoniker(pmkOther,&mkSys);
if (mkSys != MKSYS_FILEMONIKER)
return MonikerCommonPrefixWith(iface, pmkOther, ppmkPrefix);
if(mkSys==MKSYS_FILEMONIKER){
HRESULT ret;
ret = CreateBindCtx(0,&pbind);
if (FAILED(ret))
return ret;
/* create a string based on common part of the two paths */
ret = IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
if (FAILED(ret))
return ret;
ret = IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
if (FAILED(ret))
return ret;
nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
if (FAILED(nb1))
return nb1;
nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
if (FAILED(nb2))
{
free_stringtable(stringTable1);
return nb2;
}
if (nb1==0 || nb2==0)
{
free_stringtable(stringTable1);
free_stringtable(stringTable2);
return MK_E_NOPREFIX;
}
commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
if (!commonPath)
return E_OUTOFMEMORY;
ret = CreateBindCtx(0, &bindctx);
if (FAILED(ret))
return ret;
*commonPath=0;
/* create a string based on common part of the two paths */
ret = IMoniker_GetDisplayName(iface, bindctx, NULL, &pathThis);
if (FAILED(ret))
goto failed;
for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
(stringTable2[sameIdx]!=NULL) &&
(lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
ret = IMoniker_GetDisplayName(pmkOther, bindctx, NULL, &pathOther);
if (FAILED(ret))
goto failed;
if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
nb1 = FileMonikerImpl_DecomposePath(pathThis, &stringTable1);
if (FAILED(nb1)) {
ret = nb1;
goto failed;
}
machineNameCase = TRUE;
nb2 = FileMonikerImpl_DecomposePath(pathOther, &stringTable2);
if (FAILED(nb2)) {
ret = nb2;
goto failed;
}
for(i=2;i<sameIdx;i++)
if (nb1 == 0 || nb2 == 0) {
ret = MK_E_NOPREFIX;
goto failed;
}
if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
machineNameCase = FALSE;
break;
}
}
commonPath = CoTaskMemAlloc(sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
if (!commonPath) {
ret = E_OUTOFMEMORY;
goto failed;
}
if (machineNameCase && *stringTable1[sameIdx-1]=='\\')
sameIdx--;
*commonPath = 0;
for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
(stringTable2[sameIdx]!=NULL) &&
(lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
if (machineNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
ret = MK_E_NOPREFIX;
else
{
for(i=0;i<sameIdx;i++)
strcatW(commonPath,stringTable1[i]);
if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
machineNameCase = TRUE;
free_stringtable(stringTable1);
free_stringtable(stringTable2);
ret = CreateFileMoniker(commonPath,ppmkPrefix);
for(i=2;i<sameIdx;i++)
if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
machineNameCase = FALSE;
break;
}
HeapFree(GetProcessHeap(),0,commonPath);
return ret;
}
if (machineNameCase && *stringTable1[sameIdx-1]=='\\')
sameIdx--;
if (machineNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
ret = MK_E_NOPREFIX;
else
return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
{
for (i = 0; i < sameIdx; i++)
strcatW(commonPath,stringTable1[i]);
ret = CreateFileMoniker(commonPath, ppmkPrefix);
}
failed:
IBindCtx_Release(bindctx);
CoTaskMemFree(pathThis);
CoTaskMemFree(pathOther);
CoTaskMemFree(commonPath);
free_stringtable(stringTable1);
free_stringtable(stringTable2);
return ret;
}
/******************************************************************************
......@@ -1105,8 +1106,7 @@ lend:
CoTaskMemFree(strgtable);
}
if (word)
CoTaskMemFree(word);
CoTaskMemFree(word);
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment