Alex Henrie : ole32: Fix memory leak in FileMonikerImpl_ComposeWith.

Alexandre Julliard julliard at wine.codeweavers.com
Wed May 4 11:38:21 CDT 2016


Module: wine
Branch: master
Commit: 776eebe80b9322325af44ccc6d743ba918d92b4b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=776eebe80b9322325af44ccc6d743ba918d92b4b

Author: Alex Henrie <alexhenrie24 at gmail.com>
Date:   Mon May  2 19:00:05 2016 -0600

ole32: Fix memory leak in FileMonikerImpl_ComposeWith.

Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ole32/filemoniker.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/dlls/ole32/filemoniker.c b/dlls/ole32/filemoniker.c
index 9586be9..3cd7da4 100644
--- a/dlls/ole32/filemoniker.c
+++ b/dlls/ole32/filemoniker.c
@@ -694,39 +694,39 @@ FileMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
         lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
 
         if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
-            return MK_E_SYNTAX;
-
-        if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
-            lastIdx1--;
+            res = MK_E_SYNTAX;
+        else{
+            if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
+                lastIdx1--;
 
-        /* for etch "..\" in the left of str2 remove the right element from str1 */
-        for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
+            /* for each "..\" in the left of str2 remove the right element from str1 */
+            for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ); i+=2){
 
-            lastIdx1-=2;
-        }
+                lastIdx1-=2;
+            }
 
-        /* the length of the composed path string  is raised by the sum of the two paths lengths  */
-        newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
+            /* the length of the composed path string is increased by the sum of the two paths' lengths */
+            newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
 
-        if (newStr)
-        {
-            /* new path is the concatenation of the rest of str1 and str2 */
-            for(*newStr=0,j=0;j<=lastIdx1;j++)
-                strcatW(newStr,strDec1[j]);
+            if (newStr){
+                /* new path is the concatenation of the rest of str1 and str2 */
+                for(*newStr=0,j=0;j<=lastIdx1;j++)
+                    strcatW(newStr,strDec1[j]);
 
-            if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
-                strcatW(newStr,bkSlash);
+                if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
+                    strcatW(newStr,bkSlash);
 
-            for(j=i;j<=lastIdx2;j++)
-                strcatW(newStr,strDec2[j]);
+                for(j=i;j<=lastIdx2;j++)
+                    strcatW(newStr,strDec2[j]);
 
-            /* create a new moniker with the new string */
-            res=CreateFileMoniker(newStr,ppmkComposite);
+                /* create a new moniker with the new string */
+                res=CreateFileMoniker(newStr,ppmkComposite);
 
-            /* free all strings space memory used by this function */
-            HeapFree(GetProcessHeap(),0,newStr);
+                /* free string memory used by this function */
+                HeapFree(GetProcessHeap(),0,newStr);
+            }
+            else res = E_OUTOFMEMORY;
         }
-        else res = E_OUTOFMEMORY;
 
         free_stringtable(strDec1);
         free_stringtable(strDec2);




More information about the wine-cvs mailing list