While running peakperf --list, the program frequently experiences a segmentation fault.
Cause:
The core structures (benchmark, benchmark_cpu, and cpu) are allocated using malloc, which does not zero out memory. Since the --list execution path is very short, it often exits before all internal pointers are assigned values or set to NULL. The cleanup functions (free_hardware, exit_benchmark, free_benchmark_cpu) then attempt to free() garbage pointers, leading to the crash.
Fix:
Initialize all allocated structures to zero using memset immediately after malloc. This ensures that all pointers are NULL by default, making the cleanup sequence safe. I also found a math error in print_bench_types_cpu where a negative value was passed to printf's width specifier, which I have corrected.
I will submit a PR with the fix shortly.
While running
peakperf --list, the program frequently experiences a segmentation fault.Cause:
The core structures (
benchmark,benchmark_cpu, andcpu) are allocated usingmalloc, which does not zero out memory. Since the--listexecution path is very short, it often exits before all internal pointers are assigned values or set toNULL. The cleanup functions (free_hardware,exit_benchmark,free_benchmark_cpu) then attempt tofree()garbage pointers, leading to the crash.Fix:
Initialize all allocated structures to zero using
memsetimmediately aftermalloc. This ensures that all pointers areNULLby default, making the cleanup sequence safe. I also found a math error inprint_bench_types_cpuwhere a negative value was passed toprintf's width specifier, which I have corrected.I will submit a PR with the fix shortly.