google / benchmark

A microbenchmark support library
Apache License 2.0
8.89k stars 1.61k forks source link

[FR] clang static analyzer: `src/include/benchmark/benchmark.h:1069:3: Potential memory leak [cplusplus.NewDeleteLeaks]` #1513

Closed LebedevRI closed 1 year ago

LebedevRI commented 1 year ago

https://github.com/darktable-org/rawspeed/actions/runs/3574871458/jobs/6011864553#step:23:314 https://github.com/google/benchmark/blob/2257fa4d6afb8e5a2ccd510a70f38fe7fcdf1edf/include/benchmark/benchmark.h#L1272-L1276 triggers clang static analyzer reports:

[HIGH] /__w/rawspeed/rawspeed/rawspeed-build/src/external/googlebenchmark/src/include/benchmark/benchmark.h:1069:3: Potential memory leak [cplusplus.NewDeleteLeaks]
  return internal::RegisterBenchmarkInternal(
  ^

Found 1 defect(s) in benchmark.h

It would be really good to either completely rewrite that code to avoid the issue in the first place, or at least silence it as a known false-positive.

HFTrader commented 1 year ago

I could not replicate this. Using clang 17 (trunk) and benchmark/main as of today.

LebedevRI commented 1 year ago

Still happening: https://github.com/darktable-org/rawspeed/actions/runs/4367100895/jobs/7637984919#step:29:275

dmah42 commented 1 year ago

can we add that static analysis to the benchmark CI bots?

LebedevRI commented 1 year ago

Still happening: https://github.com/darktable-org/rawspeed/actions/runs/4367100895/jobs/7637984919#step:29:275

(Err, of course that is with clang-15, maybe it's gone in clang-16, i don't know yet.)

HFTrader commented 1 year ago

How did you run? Just scan-build make?

LebedevRI commented 1 year ago

As you can see in that very log, by running CodeChecker over the compile_commands.json.

HFTrader commented 1 year ago

It looks like CodeChecker uses scan-build under the hood, right? Let me try with clang-15 or earlier.

LebedevRI commented 1 year ago

Yup, the warning is still there with clang-16, as expected: https://github.com/darktable-org/rawspeed/actions/runs/5428151349/jobs/9872094540?pr=494

Also, is anyone familiar why benchmarks that are linked to shared libraries may fail with Exit code 0xc0000135? https://github.com/darktable-org/rawspeed/actions/runs/5428151349/jobs/9872096202?pr=494