[Lldb-commits] [PATCH] D68638: [lldb] Avoid resource leak

Konrad Wilhelm Kleine via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 8 06:51:40 PDT 2019


kwk created this revision.
kwk added a reviewer: jankratochvil.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Before the pointer variable `args_dict` was assigned the result of an
allocation with `new` and then `args_dict` is passed to
`GetValueForKeyAsDictionary` which immediatly and unconditionally
assigns `args_dict` to `nullptr`:

  bool GetValueForKeyAsDictionary(llvm::StringRef key,
                                  Dictionary *&result) const {
    result = nullptr;

This caused a memory leak which was found in my coverity scan instance
under CID 224753: https://scan.coverity.com/projects/kwk-llvm-project.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68638

Files:
  lldb/source/Breakpoint/BreakpointResolverScripted.cpp


Index: lldb/source/Breakpoint/BreakpointResolverScripted.cpp
===================================================================
--- lldb/source/Breakpoint/BreakpointResolverScripted.cpp
+++ lldb/source/Breakpoint/BreakpointResolverScripted.cpp
@@ -92,7 +92,7 @@
   depth = (lldb::SearchDepth) depth_as_int;
   
   StructuredDataImpl *args_data_impl = new StructuredDataImpl();
-  StructuredData::Dictionary *args_dict = new StructuredData::Dictionary();
+  StructuredData::Dictionary *args_dict = nullptr;
   success = options_dict.GetValueForKeyAsDictionary(
     GetKey(OptionNames::ScriptArgs), args_dict);
   if (success) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68638.223841.patch
Type: text/x-patch
Size: 629 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191008/dc8e63b1/attachment-0001.bin>


More information about the lldb-commits mailing list