From 58230f89ccc41ac9496193aec241e51ee703d393 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Wed, 16 Mar 2011 16:46:37 +0000 Subject: [PATCH] [SHELL32] Thomas Faber - Fix memory leak in RenderHDROP. Modifications by me to have just a single return statement in the function. See issue #5998 for more details. svn path=/trunk/; revision=51069 --- reactos/dll/win32/shell32/clipboard.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/reactos/dll/win32/shell32/clipboard.c b/reactos/dll/win32/shell32/clipboard.c index 0c989c6ddd5..24fd0d0f514 100644 --- a/reactos/dll/win32/shell32/clipboard.c +++ b/reactos/dll/win32/shell32/clipboard.c @@ -49,15 +49,16 @@ HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) UINT i; int size = 0; WCHAR wszFileName[MAX_PATH]; - HGLOBAL hGlobal; + HGLOBAL hGlobal = NULL; DROPFILES *pDropFiles; int offset; LPITEMIDLIST *pidls; TRACE("(%p,%p,%u)\n", pidlRoot, apidl, cidl); - pidls = HeapAlloc(GetProcessHeap(), 0, cidl * sizeof *pidls); - if (!pidls) return NULL; + pidls = HeapAlloc(GetProcessHeap(), 0, cidl * sizeof(*pidls)); + if (!pidls) + goto cleanup; /* get the size needed */ size = sizeof(DROPFILES); @@ -73,7 +74,8 @@ HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) /* Fill the structure */ hGlobal = GlobalAlloc(GHND|GMEM_SHARE, size); - if(!hGlobal) return hGlobal; + if(!hGlobal) + goto cleanup; pDropFiles = (DROPFILES *)GlobalLock(hGlobal); offset = (sizeof(DROPFILES) + sizeof(WCHAR) - 1) / sizeof(WCHAR); @@ -91,7 +93,9 @@ HGLOBAL RenderHDROP(LPITEMIDLIST pidlRoot, LPITEMIDLIST * apidl, UINT cidl) ((WCHAR*)pDropFiles)[offset] = 0; GlobalUnlock(hGlobal); - HeapFree(GetProcessHeap(), 0, pidls); +cleanup: + if(pidls) + HeapFree(GetProcessHeap(), 0, pidls); return hGlobal; }