This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Avoid resource leak
ClosedPublic

Authored by kwk on Oct 8 2019, 6:48 AM.

Details

Summary

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.

Event Timeline

kwk created this revision.Oct 8 2019, 6:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 8 2019, 6:48 AM
teemperor accepted this revision.Oct 8 2019, 7:15 AM
teemperor added a subscriber: teemperor.

LGTM. Also, this whole function seems to have no tests. So if you find an easy way to test this, then please add a test to functionalities/breakpoint/scripted_bkpt/TestScriptedResolver.py. You can also check this in as-is if the test turns out to be too complicated (I'm not a big fan of the whole "you touched my spaghetti so you also have to come up with a way to test the whole thing".)

This revision is now accepted and ready to land.Oct 8 2019, 7:15 AM
This revision was automatically updated to reflect the committed changes.