Skip to content

Fix memory leak of StaticOMPArg array in vecenv#521

Open
Bortlesboat wants to merge 1 commit intoPufferAI:4.0from
Bortlesboat:fix/vecenv-thread-args-memleak
Open

Fix memory leak of StaticOMPArg array in vecenv#521
Bortlesboat wants to merge 1 commit intoPufferAI:4.0from
Bortlesboat:fix/vecenv-thread-args-memleak

Conversation

@Bortlesboat
Copy link
Copy Markdown

The StaticOMPArg array allocated in create_static_threads() is assigned to a local pointer that goes out of scope when the function returns. Since static_vec_close() has no reference to it, the array is never freed — leaking buffers * sizeof(StaticOMPArg) bytes per thread pool creation.

This stores the pointer in StaticThreading so static_vec_close can free it after joining all threads.

Changes:

  • Forward-declare StaticOMPArg so StaticThreading can hold a pointer to it
  • Add thread_args field to StaticThreading
  • Store the calloc'd array in vec->threading->thread_args
  • Free it in static_vec_close alongside the other threading allocations

Safe because by the time static_vec_close runs, the shutdown flag is set and all threads have been joined — no thread is still referencing the args.

The StaticOMPArg array allocated in create_static_threads was assigned
to a local pointer that went out of scope, leaking
(buffers * sizeof(StaticOMPArg)) bytes per thread pool creation.

Store the pointer in StaticThreading so static_vec_close can free it
after joining all threads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant