Sven Baars : mstask: Fix some memory leaks on error path (Valgrind).

Alexandre Julliard julliard at winehq.org
Wed Feb 6 15:32:28 CST 2019


Module: wine
Branch: master
Commit: 3804b99e7253a13b383549a6a851e80300841cc5
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=3804b99e7253a13b383549a6a851e80300841cc5

Author: Sven Baars <sven.wine at gmail.com>
Date:   Wed Feb  6 11:48:18 2019 +0100

mstask: Fix some memory leaks on error path (Valgrind).

Signed-off-by: Sven Baars <sven.wine at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mstask/task.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/dlls/mstask/task.c b/dlls/mstask/task.c
index 6c27b76..9a39fc9 100644
--- a/dlls/mstask/task.c
+++ b/dlls/mstask/task.c
@@ -1690,7 +1690,11 @@ static HRESULT WINAPI MSTASK_IPersistFile_Save(IPersistFile *iface, LPCOLESTR ta
         hfile = CreateFileW(task_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, disposition, 0, 0);
         if (hfile != INVALID_HANDLE_VALUE) break;
 
-        if (try++ >= 3) return HRESULT_FROM_WIN32(GetLastError());
+        if (try++ >= 3)
+        {
+            hr = HRESULT_FROM_WIN32(GetLastError());
+            goto failed;
+        }
         Sleep(100);
     }
 
@@ -1781,13 +1785,16 @@ failed:
         CoTaskMemFree(comment);
     CoTaskMemFree(user_data);
 
-    CloseHandle(hfile);
-    if (hr != S_OK)
-        DeleteFileW(task_name);
-    else if (remember)
+    if (hfile != INVALID_HANDLE_VALUE)
     {
-        heap_free(This->task_name);
-        This->task_name = heap_strdupW(task_name);
+        CloseHandle(hfile);
+        if (hr != S_OK)
+            DeleteFileW(task_name);
+        else if (remember)
+        {
+            heap_free(This->task_name);
+            This->task_name = heap_strdupW(task_name);
+        }
     }
     return hr;
 }




More information about the wine-cvs mailing list