[BUG] Potential memory leak when registering a benchmark with a lambda
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 1.8k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 8
Description
**Describe the bug**
clang analyzer / clang-tidy 13 reports "Potential memory leak" when registering a benchmark with a lambda.
```
include/benchmark/benchmark.h:1193:3: error: Potential memory leak [clang-analyzer-cplusplus.NewDeleteLeaks,-warnings-as-errors]
return internal::RegisterBenchmarkInternal(
^
bench.cpp:169:13: note: Calling 'RegisterBenchmark<(lambda at bench.cpp:169:71)>'
RegisterBenchmark("name", [&b](State& state) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/benchmark/benchmark.h:1194:7: note: Memory is allocated
::new BenchType(name, std::forward(fn)));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/benchmark/benchmark.h:1193:3: note: Potential memory leak
return internal::RegisterBenchmarkInternal(
^
1 warning treated as error
```
I confirmed that clang-tidy with "clang-analyzer-*" checks enabled was recently added to this project but it didn't report any issues.
There is no easy way to suppress the warning because it would need to be done in the benchmark.h header.
Contributor guide
Assessment
This issue has not been assessed yet.