kernel32: fix memory leak in CopyFileW

Lionel_Debroux lionel_debroux at yahoo.fr
Thu Aug 30 04:37:58 CDT 2007


CopyFileW leaks 65536 bytes of heap memory in some error paths. Found in
Michael Stefaniuc's list of Wine potential bugs detected by Smatch.

2007-08-30  Lionel Debroux <lionel_debroux at yahoo.fr>
       * dlls/kernel32/path.c:
       kernel32: Fix memory leak in CopyFileW (found by Smatch).
-------------- next part --------------
>From f5718c853427d76c1f807a4202e71a7e7d550ebf Mon Sep 17 00:00:00 2001
From: Lionel Debroux <lionel_debroux at yahoo.fr>
Date: Thu, 30 Aug 2007 10:28:20 +0200
Subject: Fixed memory leak in CopyFileW (found by Smatch).

---
 dlls/kernel32/path.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index eb752f0..7932df0 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -879,12 +879,14 @@ BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
                      NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
     {
         WARN("Unable to open source %s\n", debugstr_w(source));
+        HeapFree( GetProcessHeap(), 0, buffer );
         return FALSE;
     }
 
     if (!GetFileInformationByHandle( h1, &info ))
     {
         WARN("GetFileInformationByHandle returned error for %s\n", debugstr_w(source));
+        HeapFree( GetProcessHeap(), 0, buffer );
         CloseHandle( h1 );
         return FALSE;
     }
@@ -894,6 +896,7 @@ BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
                              info.dwFileAttributes, h1 )) == INVALID_HANDLE_VALUE)
     {
         WARN("Unable to open dest %s\n", debugstr_w(dest));
+        HeapFree( GetProcessHeap(), 0, buffer );
         CloseHandle( h1 );
         return FALSE;
     }
-- 
1.4.4.4



More information about the wine-patches mailing list