From 23f145daa50c3f51a7fb8c8d68c55e5f4a8027c2 Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Thu, 8 Dec 2022 16:37:43 -0800 Subject: [PATCH] [NFC] Fix leak in command options configuration. `m_options.Append(new OptionPermissions())` leaks because the pointer passed in is not owned. Use a class member to ensure lifetime, which is the common pattern used for this API. Found by the LLDB command interpreter fuzzer. The fuzz input is running `ap $` twice. --- lldb/source/Commands/CommandObjectPlatform.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 98c6a3b..d72dd06 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -456,12 +456,13 @@ public: Options *GetOptions() override { if (!m_options.DidFinalize()) { - m_options.Append(new OptionPermissions()); + m_options.Append(&m_option_permissions); m_options.Finalize(); } return &m_options; } + OptionPermissions m_option_permissions; OptionGroupOptions m_options; }; @@ -519,12 +520,13 @@ public: Options *GetOptions() override { if (!m_options.DidFinalize()) { - m_options.Append(new OptionPermissions()); + m_options.Append(&m_option_permissions); m_options.Finalize(); } return &m_options; } + OptionPermissions m_option_permissions; OptionGroupOptions m_options; }; -- 2.7.4