From a57a67c59b3f7529f4aa30009b214248772b544b Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 27 May 2020 14:26:15 -0700 Subject: [PATCH] Fix a use-after-free in GetXcodeSDKPath Introduced in https://reviews.llvm.org/D80595. Thanks Jonas for noticing! Differential Revision: https://reviews.llvm.org/D80666 --- lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm index cb6f03465ef7..615f77b2dbcc 100644 --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -370,7 +370,6 @@ llvm::StringRef HostInfoMacOSX::GetXcodeSDKPath(XcodeSDK sdk) { auto it = g_sdk_path.find(sdk.GetString()); if (it != g_sdk_path.end()) return it->second; - std::string path = GetXcodeSDK(sdk); - g_sdk_path.insert({sdk.GetString(), path}); - return path; + auto it_new = g_sdk_path.insert({sdk.GetString(), GetXcodeSDK(sdk)}); + return it_new.first->second; }