This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] WIP: MallocChecker: Release temporary CXXNewExpr
AbandonedPublic

Authored by Charusso on Jun 10 2019, 1:10 PM.

Diff Detail

Event Timeline

Charusso created this revision.Jun 10 2019, 1:10 PM
Charusso planned changes to this revision.EditedJun 10 2019, 1:12 PM

This is heavily WIP as sometimes we have to release a new after we return it or a constructor did something with that. The direction is okay?

NoQ added a comment.Jun 10 2019, 7:11 PM

In such cases i recommend starting with writing down a test. Like in TDD: first test, then code.

The general direction doesn't seem reasonable to me; it introduces some pattern-matching for a specific scenario, but it's unclear why is this scenario a problem on its own. We might eventually do something similar, but I recommend fully debugging the false positive - i.e., understanding what exactly is wrong with it, before picking a suppression mechanism.

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
1119–1122

I think it's clearly too early for marking the pointer as released. I.e., what about:

auto x = std::shared_ptr(new int); // the pointer is marked as released
use(x.get()); // use-after-free???
Charusso abandoned this revision.Jun 24 2019, 10:05 AM

The seen error solved by D63720.