ole32: Fix leaks on error paths (Coverity).
This commit is contained in:
parent
43b5f46fcd
commit
4768ac4413
|
@ -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;
|
||||
|
||||
*commonPath=0;
|
||||
|
||||
for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
|
||||
(stringTable2[sameIdx]!=NULL) &&
|
||||
(lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
|
||||
|
||||
if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
|
||||
|
||||
machineNameCase = TRUE;
|
||||
|
||||
for(i=2;i<sameIdx;i++)
|
||||
|
||||
if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
|
||||
machineNameCase = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (machineNameCase && *stringTable1[sameIdx-1]=='\\')
|
||||
sameIdx--;
|
||||
|
||||
if (machineNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
|
||||
ret = MK_E_NOPREFIX;
|
||||
else
|
||||
{
|
||||
for(i=0;i<sameIdx;i++)
|
||||
strcatW(commonPath,stringTable1[i]);
|
||||
|
||||
free_stringtable(stringTable1);
|
||||
free_stringtable(stringTable2);
|
||||
ret = CreateFileMoniker(commonPath,ppmkPrefix);
|
||||
}
|
||||
HeapFree(GetProcessHeap(),0,commonPath);
|
||||
ret = CreateBindCtx(0, &bindctx);
|
||||
if (FAILED(ret))
|
||||
return ret;
|
||||
|
||||
/* create a string based on common part of the two paths */
|
||||
ret = IMoniker_GetDisplayName(iface, bindctx, NULL, &pathThis);
|
||||
if (FAILED(ret))
|
||||
goto failed;
|
||||
|
||||
ret = IMoniker_GetDisplayName(pmkOther, bindctx, NULL, &pathOther);
|
||||
if (FAILED(ret))
|
||||
goto failed;
|
||||
|
||||
nb1 = FileMonikerImpl_DecomposePath(pathThis, &stringTable1);
|
||||
if (FAILED(nb1)) {
|
||||
ret = nb1;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
nb2 = FileMonikerImpl_DecomposePath(pathOther, &stringTable2);
|
||||
if (FAILED(nb2)) {
|
||||
ret = nb2;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (nb1 == 0 || nb2 == 0) {
|
||||
ret = MK_E_NOPREFIX;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
commonPath = CoTaskMemAlloc(sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
|
||||
if (!commonPath) {
|
||||
ret = E_OUTOFMEMORY;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
*commonPath = 0;
|
||||
for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
|
||||
(stringTable2[sameIdx]!=NULL) &&
|
||||
(lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
|
||||
|
||||
if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
|
||||
machineNameCase = TRUE;
|
||||
|
||||
for(i=2;i<sameIdx;i++)
|
||||
if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
|
||||
machineNameCase = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue