Author: Jonas Devlieghere Date: 2022-02-16T09:05:08-08:00 New Revision: 0c58e9f4a474c60ed863e6a66c0e1202b4bd6c78
URL: https://github.com/llvm/llvm-project/commit/0c58e9f4a474c60ed863e6a66c0e1202b4bd6c78 DIFF: https://github.com/llvm/llvm-project/commit/0c58e9f4a474c60ed863e6a66c0e1202b4bd6c78.diff LOG: [lldb] Fix memory leak in CommandObjectType Avoid leaking the ScriptAddOptions or SynthAddOptions when we return early because of an empty type name. Added: Modified: lldb/source/Commands/CommandObjectType.cpp Removed: ################################################################################ diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index f9e1d0f91fb76..f4ecd80fb0210 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -1337,9 +1337,9 @@ bool CommandObjectTypeSummaryAdd::Execute_ScriptSummary( m_options.m_flags, funct_name_str.c_str(), code.c_str()); } else { // Use an IOHandler to grab Python code from the user - ScriptAddOptions *options = - new ScriptAddOptions(m_options.m_flags, m_options.m_regex, - m_options.m_name, m_options.m_category); + auto options = std::make_unique<ScriptAddOptions>( + m_options.m_flags, m_options.m_regex, m_options.m_name, + m_options.m_category); for (auto &entry : command.entries()) { if (entry.ref().empty()) { @@ -1351,10 +1351,10 @@ bool CommandObjectTypeSummaryAdd::Execute_ScriptSummary( } m_interpreter.GetPythonCommandsFromIOHandler( - " ", // Prompt - *this, // IOHandlerDelegate - options); // Baton for the "io_handler" that will be passed back into - // our IOHandlerDelegate functions + " ", // Prompt + *this, // IOHandlerDelegate + options.release()); // Baton for the "io_handler" that will be passed + // back into our IOHandlerDelegate functions result.SetStatus(eReturnStatusSuccessFinishNoResult); return result.Succeeded(); @@ -2252,7 +2252,7 @@ class CommandObjectTypeSynthClear : public CommandObjectTypeFormatterClear { bool CommandObjectTypeSynthAdd::Execute_HandwritePython( Args &command, CommandReturnObject &result) { - SynthAddOptions *options = new SynthAddOptions( + auto options = std::make_unique<SynthAddOptions>( m_options.m_skip_pointers, m_options.m_skip_references, m_options.m_cascade, m_options.m_regex, m_options.m_category); @@ -2266,10 +2266,10 @@ bool CommandObjectTypeSynthAdd::Execute_HandwritePython( } m_interpreter.GetPythonCommandsFromIOHandler( - " ", // Prompt - *this, // IOHandlerDelegate - options); // Baton for the "io_handler" that will be passed back into our - // IOHandlerDelegate functions + " ", // Prompt + *this, // IOHandlerDelegate + options.release()); // Baton for the "io_handler" that will be passed back + // into our IOHandlerDelegate functions result.SetStatus(eReturnStatusSuccessFinishNoResult); return result.Succeeded(); } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits