[clang] [analyzer] Remove redundant bug type DoubleDelete (PR #147542)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 9 02:10:23 PDT 2025
================
@@ -412,7 +412,7 @@ class DerefClass{
void testDoubleDeleteClassInstance() {
DerefClass *foo = new DerefClass();
delete foo;
- delete foo; // newdelete-warning {{Attempt to delete released memory}}
+ delete foo; // newdelete-warning {{Attempt to free released memory}}
----------------
NagyDonat wrote:
There are already many situations where `cplusplus.NewDelete` encounters repeated `delete` expressions and produces a `DoubleFree` bug report with "Attempt to free released memory" as the message, see e.g. https://github.com/llvm/llvm-project/blob/962c4217bc68c7b9a138b92dd7a30e2a277e479b/clang/test/Analysis/NewDelete-path-notes.cpp#L19
The `DoubleDelete` bug (which I want to remove / merge into `DoubleFree`) is only emitted in the special case when a nontrivial (?) destructor of the deleted type would be called, and it was introduced because in this case the body of the destructor is executed before the point where the `DoubleFree` bug is produced, so if the body of the destructor references a member variable, then (without the `DoubleDelete` code) we would get a use-after-free report instead of the `DoubleFree` (which is technically correct, but less elegant).
I think it's important that the warning message produced by `delete foo; delete foo;` should not depend on whether `*foo` has a destructor or not, so in this commit I would like to keep the "Attempt to free released memory" spelling.
I would gladly accept a separate followup PR that replaces "free" with a more accurate word, e.g. by
- changing the message to "Attempt to release already released memory";
- or using "delete" in _all_ the `DoubleFree` reports that involve `delete` operators (and not just those that come through the `DoubleDelete` logic).
However, I don't have capacity for implementing this, as I'm already deep in the "also solve this tangentially related issue" mode.
https://github.com/llvm/llvm-project/pull/147542
More information about the cfe-commits
mailing list