From 263f378afcb91aa0eca8f6d7a0c17e70fa06a1c9 Mon Sep 17 00:00:00 2001 From: xyz1001 Date: Thu, 7 Sep 2023 11:33:37 +0800 Subject: [PATCH] Fix memory leak when call GetThreadDescription --- public/common/TracySystem.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/public/common/TracySystem.cpp b/public/common/TracySystem.cpp index 05a16c43..0d79ad30 100644 --- a/public/common/TracySystem.cpp +++ b/public/common/TracySystem.cpp @@ -219,12 +219,15 @@ TRACY_API const char* GetThreadName( uint32_t id ) if( hnd != 0 ) { PWSTR tmp; - _GetThreadDescription( hnd, &tmp ); - auto ret = wcstombs( buf, tmp, 256 ); - CloseHandle( hnd ); - if( ret != static_cast(-1) ) + if ( SUCCEEDED( _GetThreadDescription( hnd, &tmp ) ) ) { - return buf; + auto ret = wcstombs( buf, tmp, 256 ); + CloseHandle( hnd ); + LocalFree( tmp ); + if( ret != static_cast(-1) ) + { + return buf; + } } } }