Repository navigation
fix(amdsmi): stop leaking processors when exiting without shutdown - #13007
Merged
Merged
Conversation
- Allocate the AMDSmiSystem singleton once and never destroy it. When a process exited without amdsmi_shut_down(), destroying the static freed only its containers, so every GPU, CPU and NIC object it owned was reported as a leak and the exit failed under LeakSanitizer - Keep it alive rather than freeing those objects at exit, since a thread can still be inside the library while static destructors run - Add a death test that exits a fresh process right after amdsmi_init() without amdsmi_shut_down(); under LeakSanitizer a leak fails it Signed-off-by: Adam360x <Adam.pryor@amd.com>
✅ All Policy Checks Passed
📖 Need help? See the Policy FAQ for details on every check and how to fix failures. |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Heap allocation removes implicit zero-initialization, leaving members indeterminate and allowing combined GPU/NIC initialization to crash.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Extends #12362’s lifetime approach to AMD-SMI’s system singleton, preventing exit-time leak reports when shutdown is omitted.
Changes:
- Keeps the singleton alive until process termination while preserving explicit shutdown.
- Adds a subprocess regression test for initialization followed by exit without shutdown.
| File | Description |
|---|---|
| projects/amdsmi/tests/amd_smi_test/functional/system/exit_without_shutdown_test.cc | Tests exit without shutdown under LeakSanitizer. |
| projects/amdsmi/src/amd_smi/amd_smi_system.cc | Replaces the destructed static singleton with permanent heap storage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Give ainic_ctx_ and AMDSmiDrm::vendor_id default member initializers. The static system object was zero-initialized before construction; the heap-allocated one is not, so both started indeterminate, and retrying amdsmi_init() with NIC flags after an init that failed partway could pass a garbage context to smi_nic_destroy_context() Signed-off-by: Adam360x <Adam.pryor@amd.com>
gabrpham
approved these changes
Oct 8, 2026
bill-shuzhou-liu
approved these changes
Oct 8, 2026
Contributor
TheRock Submodule Bump ActivityNewest first
|
anujshuk-amd
pushed a commit
that referenced
this pull request
Oct 12, 2026
…13007) ## Motivation A process that calls `amdsmi_init()` and exits without `amdsmi_shut_down()` leaks every socket and processor object the library created, so under LeakSanitizer its exit fails with code 1 (for example, a tool that only prints `--version`). Same ownership fix as #12362, one level up. Signed-off-by: Adam360x <Adam.pryor@amd.com>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
A process that calls
amdsmi_init()and exits withoutamdsmi_shut_down()leaks every socket and processor object the library created, so under LeakSanitizer its exit fails with code 1 (for example, a tool that only prints--version). Same ownership fix as #12362, one level up.Technical Details
Library (
src/amd_smi/amd_smi_system.cc):AMDSmiSystem::getInstance()allocates the system once and never destroys it, so the GPU, CPU and NIC objects it owns stay reachable until the process ends. The function-local static it replaces was destroyed at exit, which freed only its containers and left those objects unreachableamdsmi_shut_down()still frees everything; init and shut-down cycles are unchangeddlclose()leaves the system object (about 0.5 KB) unreachable, as it already does fix(amdsmi): stop leaking the per-GPU process-list cache #12362's mapHeaders (
include/amd_smi/impl/amd_smi_system.h,include/amd_smi/impl/amd_smi_drm.h):nullptr,0). The static object was zero-initialized before its constructor ran; the heap object is not, so both would otherwise start indeterminateTests (
tests/amd_smi_test/functional/system/exit_without_shutdown_test.cc):SystemFunctionalReadOnly.ExitWithoutShutDownIsClean: a threadsafe death test re-runs itself in a fresh process that exits right afteramdsmi_init()withoutamdsmi_shut_down(), and expects exit code 0. In the AMDSMI ASAN GPU job, LeakSanitizer turns a leak into a failureNo public header, wrapper, CLI or docs change. No CHANGELOG entry: the leak only shows up at exit.
Issue Tracking
JIRA ID: TBD (ticket to be created)
Test Plan
-DADDRESS_SANITIZER=ON -DBUILD_TESTS=ON) with the CI'sASAN_OPTIONSandLSAN_OPTIONS, A/B against the same build with only the library change reverted:AMDSMI_NON_PRIVILEGED=1: fullamdsmitst*Unit*:GpuFunctionalReadOnly.*:SystemFunctionalReadOnly.*amdsmi_init()with the GPU, CPU, NIC and combined flags and exits withoutamdsmi_shut_down()amdsmi_init()with GPU and NIC flags after forcing the first call to fail once rocm_smi is initializedSystemFunctionalReadOnly.*, 3 runspre-commitwithprojects/amdsmi/.pre-commit-config.yamlTest Result
0xbebe...). The forced retry crashed insmi_nic_destroy_context()without the initializers and succeeds with themSubmission Checklist