Skip to content

Segmentation fault during --list due to uninitialized memory #30

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions