sfx2/source/appl/shutdowniconw32.cxx |   15 ++++++++-------
 sfx2/source/doc/syspathw32.cxx       |   21 +++++++++++----------
 2 files changed, 19 insertions(+), 17 deletions(-)

New commits:
commit 1ddc294779d81ce2a00b75d283f183890074e650
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri Apr 26 11:42:35 2024 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Apr 30 11:19:15 2024 +0200

    Unchecked HeapAlloc
    
    Change-Id: Icd49d0b5f996d57d8e9518cb08fd3c3fc54fa779
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166732
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit a70a8f55973ec3e71f65335be75699f1d2a73d62)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166833
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sfx2/source/appl/shutdowniconw32.cxx 
b/sfx2/source/appl/shutdowniconw32.cxx
index 2fb7cd2b7875..a237aac13547 100644
--- a/sfx2/source/appl/shutdowniconw32.cxx
+++ b/sfx2/source/appl/shutdowniconw32.cxx
@@ -681,15 +681,16 @@ static OUString SHGetSpecialFolder( int nFolderID )
 
     if( hHdl == NOERROR )
     {
-        WCHAR *lpFolderA;
-        lpFolderA = ALLOC( WCHAR, 16000 );
-
-        SHGetPathFromIDListW( pidl, lpFolderA );
-        aFolder = o3tl::toU( lpFolderA );
+        if (WCHAR *lpFolderA = ALLOC(WCHAR, 16000))
+        {
+            SHGetPathFromIDListW(pidl, lpFolderA);
+            aFolder = o3tl::toU(lpFolderA);
 
-        FREE( lpFolderA );
-        SHFree_( pidl );
+            FREE(lpFolderA);
+            SHFree_(pidl);
+        }
     }
+
     return aFolder;
 }
 
diff --git a/sfx2/source/doc/syspathw32.cxx b/sfx2/source/doc/syspathw32.cxx
index f60f459829d7..dce19e3625c0 100644
--- a/sfx2/source/doc/syspathw32.cxx
+++ b/sfx2/source/doc/syspathw32.cxx
@@ -37,17 +37,18 @@ static bool SHGetSpecialFolderW32( int nFolderID, WCHAR* 
pszFolder, int nSize )
 
     if( hHdl == NOERROR )
     {
-        WCHAR *lpFolder = static_cast< WCHAR* >( HeapAlloc( GetProcessHeap(), 
0, 16000 ));
-
-        SHGetPathFromIDListW( pidl, lpFolder );
-        wcsncpy( pszFolder, lpFolder, nSize );
-
-        HeapFree( GetProcessHeap(), 0, lpFolder );
-        IMalloc *pMalloc;
-        if( NOERROR == SHGetMalloc(&pMalloc) )
+        if (WCHAR *lpFolder = static_cast<WCHAR*>(HeapAlloc(GetProcessHeap(), 
0, 16000)))
         {
-            pMalloc->Free( pidl );
-            pMalloc->Release();
+            SHGetPathFromIDListW( pidl, lpFolder );
+            wcsncpy( pszFolder, lpFolder, nSize );
+
+            HeapFree( GetProcessHeap(), 0, lpFolder );
+            IMalloc *pMalloc;
+            if( NOERROR == SHGetMalloc(&pMalloc) )
+            {
+                pMalloc->Free( pidl );
+                pMalloc->Release();
+            }
         }
     }
     return true;

Reply via email to