Skip to content

bug: dedx_get_ion_list() returns a thread-unsafe function-local static buffer #113

Open

Description

@grzanka

Part of #108 (health-review epic). Sub-concern of the broader thread-safety effort in #86.

Problem

For Bethe/default programs, dedx_get_ion_list() builds and returns a pointer to a function-local static array:

const int *dedx_get_ion_list(int program) {
    if (program == DEDX_BETHE_EXT00 || program == DEDX_DEFAULT) {
        static int temp[113], i;
        for (i = 0; i < 112; i++) temp[i] = i + 1;
        temp[112] = -1; // stopper
        return temp;    // TODO: Hey Jakob, er det her lovligt eller et nyt mem leak?
    } else
        return dedx_program_available_ions[program];
}

Two problems:

  1. Not thread-safe — concurrent callers race on the shared static buffer, and the returned pointer aliases mutable shared state.
  2. The leftover Danish // TODO … mem leak? comment indicates this was never resolved and should not ship.

Proposed change

Return a pointer to a static const precomputed, -1-terminated table (built once at compile time or guarded init), matching the immutable-static contract of the other dedx_get_*_list() functions. Remove the TODO comment.

Acceptance criteria

  • dedx_get_ion_list() returns a pointer to immutable, read-only data for all programs (no per-call mutation of shared state).
  • Behavior is unchanged: a -1-terminated list of ions 1..112 for Bethe/default.
  • The Danish TODO comment is gone.
  • No regression in test_initialize / list-related tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions