[clang] [analyzer] MallocChecker – Fix false positive leak for smart pointers in temporary objects (PR #152751)

Pavel Skripkin via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 11 10:59:52 PDT 2025


pskrgag wrote:

I am sorry, looks like I found another regression:

```cpp

#include <memory>

struct Foo {
  std::unique_ptr<int> ptr;
  int *raw;

  Foo() : ptr(std::make_unique<int>(1)), raw(new int) {}
};

void add(Foo foo) {}

int main(int argc, const char **argv) {
  add(Foo());
  return 0;
}
```

With your patch applied `raw` leak is not reported, however current CSA finds it: https://godbolt.org/z/569x11e7a.

I didn't trace why it happens, will be able to come back tomorrow.

https://github.com/llvm/llvm-project/pull/152751


More information about the cfe-commits mailing list