This is an archive of the discontinued LLVM Phabricator instance.

Fix a small memory leak in VectorType.cpp and BlockPointer.cpp
AcceptedPublic

Authored by jasonmolenda on Aug 5 2020, 9:44 PM.

Details

Reviewers
jingham
davide
Summary

Looking over the clang static analyzer, came across this old memory leak - looks like it's been around for at least four years. These two methods both call a formatters::*SyntheticFrontEndCreator method which new's an object and returns a pointer to it; they save save that pointer but never call delete. This patch puts it in an auto_ptr so it'll be destroyed when it goes out of scope.

Diff Detail

Event Timeline

jasonmolenda created this revision.Aug 5 2020, 9:44 PM
jasonmolenda requested review of this revision.Aug 5 2020, 9:44 PM

Made the change in Xcode and the indentation was off.

davide accepted this revision.Aug 5 2020, 10:04 PM

This is correct to the best of my understanding. Thank you Jason.

This revision is now accepted and ready to land.Aug 5 2020, 10:04 PM

auto_ptr is deprecated since C++11 and will be removed in C++17.

auto_ptr is deprecated since C++11 and will be removed in C++17.

@jasonmolenda you might want to use std::unique_ptr instead -- probably LLVM won't migrate to 17 for a while, but still.

And you can write it as

std::unique_ptr<SyntheticChildrenFrontEnd> synthetic_children = std::make_unique(...);

Update to std::unique_ptr -- thanks for the reminder!