Skip to content

fix(shader): replace raw new[] with std::vector in arbiter_t#340

Open
eunseo9311 wants to merge 1 commit intogpgpu-sim:devfrom
eunseo9311:fix/arbiter-memory-leak
Open

fix(shader): replace raw new[] with std::vector in arbiter_t#340
eunseo9311 wants to merge 1 commit intogpgpu-sim:devfrom
eunseo9311:fix/arbiter-memory-leak

Conversation

@eunseo9311
Copy link
Copy Markdown

Summary

  • Replace all 6 raw new[] allocations in arbiter_t with std::vector, fixing a memory leak caused by missing destructor
  • One arbiter_t exists per operand collector unit per SM, so the leak scales with GPU config size

Problem

arbiter_t::init() allocated arrays with new/new[] but the class had no destructor:

_inmatch = new int[m_num_banks];
_outmatch = new int[m_num_collectors];
_request = new int *[m_num_banks];       // + inner new int[] per bank
m_queue = new std::list<op_t>[num_banks];
m_allocated_bank = new allocation_t[num_banks];
m_allocator_rr_head = new unsigned[num_cu];

All 6 allocations leaked for the entire simulation lifetime.

Fix

Replace raw pointer members with std::vector:

std::vector<int> _inmatch;
std::vector<int> _outmatch;
std::vector<std::vector<int>> _request;
std::vector<std::list<op_t>> m_queue;
std::vector<allocation_t> m_allocated_bank;
std::vector<unsigned> m_allocator_rr_head;

init() uses resize() instead of new[]. RAII handles cleanup — no manual destructor needed.

Impact

  • No functional change — all operator[] access patterns remain identical
  • Eliminates per-SM memory leak that scales with config size
  • Simplifies constructor (no NULL init boilerplate)

Test plan

  • Build with source setup_environment release && make -j
  • Run Rodinia 2.0 hotspot on GTX1080Ti config — verify identical simulation output
  • Valgrind/ASan run to confirm leak is resolved

arbiter_t::init() allocated 6 arrays with new/new[] but the class
had no destructor, leaking all of them for the lifetime of the
simulation. One arbiter_t exists per operand collector unit per SM,
so the leak scales with GPU config size.

Replace all raw pointer members with std::vector (including the 2D
int** _request → vector<vector<int>>). This eliminates the leak
via automatic RAII destruction and removes the need for a manual
destructor entirely.

No functional change — all access patterns (operator[]) remain
identical.
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