diff options
author | Noel Grandin <noelgrandin@collabora.co.uk> | 2024-04-29 14:31:15 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-04-30 11:11:38 +0200 |
commit | a7f8882e4975e4194732506e4ffb9f7af6eb9c72 (patch) | |
tree | 239afc1f6b033ead930ef0061187c6b699719f44 /sfx2 | |
parent | 1a471e674f46699a2787e3ab74353fbe1de5c456 (diff) |
convert HeapAlloc to make_unique
which means we don't have to explicitly handle OOM, and the resulting
code is much cleaner
Change-Id: I958d6678bb2d6878dda9de6bf82c5314f168db17
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166855
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/appl/shutdowniconw32.cxx | 25 | ||||
-rw-r--r-- | sfx2/source/doc/syspathw32.cxx | 15 |
2 files changed, 6 insertions, 34 deletions
diff --git a/sfx2/source/appl/shutdowniconw32.cxx b/sfx2/source/appl/shutdowniconw32.cxx index a237aac13547..5d4c89307baf 100644 --- a/sfx2/source/appl/shutdowniconw32.cxx +++ b/sfx2/source/appl/shutdowniconw32.cxx @@ -658,20 +658,6 @@ void OnDrawItem(HWND /*hwnd*/, LPDRAWITEMSTRUCT lpdis) // code from setup2 project - -static void SHFree_( void *pv ) -{ - IMalloc *pMalloc; - if( NOERROR == SHGetMalloc(&pMalloc) ) - { - pMalloc->Free( pv ); - pMalloc->Release(); - } -} - -#define ALLOC(type, n) static_cast<type *>(HeapAlloc(GetProcessHeap(), 0, sizeof(type) * n )) -#define FREE(p) HeapFree(GetProcessHeap(), 0, p) - static OUString SHGetSpecialFolder( int nFolderID ) { @@ -681,14 +667,9 @@ static OUString SHGetSpecialFolder( int nFolderID ) if( hHdl == NOERROR ) { - if (WCHAR *lpFolderA = ALLOC(WCHAR, 16000)) - { - SHGetPathFromIDListW(pidl, lpFolderA); - aFolder = o3tl::toU(lpFolderA); - - FREE(lpFolderA); - SHFree_(pidl); - } + auto xFolder = std::make_unique<WCHAR[]>(16000); + SHGetPathFromIDListW(pidl, xFolder.get()); + aFolder = o3tl::toU(xFolder.get()); } return aFolder; diff --git a/sfx2/source/doc/syspathw32.cxx b/sfx2/source/doc/syspathw32.cxx index dce19e3625c0..38243e2ce7ac 100644 --- a/sfx2/source/doc/syspathw32.cxx +++ b/sfx2/source/doc/syspathw32.cxx @@ -37,19 +37,10 @@ static bool SHGetSpecialFolderW32( int nFolderID, WCHAR* pszFolder, int nSize ) if( hHdl == NOERROR ) { - if (WCHAR *lpFolder = static_cast<WCHAR*>(HeapAlloc(GetProcessHeap(), 0, 16000))) - { - SHGetPathFromIDListW( pidl, lpFolder ); - wcsncpy( pszFolder, lpFolder, nSize ); + auto xFolder = std::make_unique<WCHAR[]>(16000); - HeapFree( GetProcessHeap(), 0, lpFolder ); - IMalloc *pMalloc; - if( NOERROR == SHGetMalloc(&pMalloc) ) - { - pMalloc->Free( pidl ); - pMalloc->Release(); - } - } + SHGetPathFromIDListW( pidl, xFolder.get() ); + wcsncpy( pszFolder, xFolder.get(), nSize ); } return true; } |