Skip to content

clang-analyzer-cplusplus.NewDelete false-positive - does not note nullification of ptr after delete #43395

@LebedevRI

Description

@LebedevRI
Bugzilla Link 44050
Version trunk
OS Linux
CC @devincoughlin,@martong,@haoNoQ

Extended Description

This is manually reduced from a report that i got via CTU mode (yay).
The issue appears to be false-positive:

struct S {
int *storage;
~S() {
if(!storage)
return;
delete storage; // <- we can't
storage = nullptr;
}
};

S producer();

S foo() {
S imm = producer();
return imm;
}

S bar() {
S imm = foo();
return imm;
}

warning: Attempt to free released memory [clang-analyzer-cplusplus.NewDelete]
delete storage;
^

But how can that happen, after deleting we set it to nullptr?

https://godbolt.org/z/Jkusgy

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions