diff --git a/dlls/ole32/filemoniker.c b/dlls/ole32/filemoniker.c index af161fe660d..06c47987566 100644 --- a/dlls/ole32/filemoniker.c +++ b/dlls/ole32/filemoniker.c @@ -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 3 || nb2 > 3) ) - ret = MK_E_NOPREFIX; - else - { - for(i=0;i 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){ + machineNameCase = TRUE; + + for(i=2;i 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; }