Skip to content

Potential fix for code scanning alert no. 5: Incorrect allocation-error handling#16

Closed
rocm-devops wants to merge 3 commits intoamd-stagingfrom
alert-autofix-5
Closed

Potential fix for code scanning alert no. 5: Incorrect allocation-error handling#16
rocm-devops wants to merge 3 commits intoamd-stagingfrom
alert-autofix-5

Conversation

@rocm-devops
Copy link

Potential fix for https://github.com/AMD-ROCm-Internal/aqlprofile/security/code-scanning/5

To fix the issue, the redundant null pointer check after new HsaTimer should be removed. Instead, the allocation failure should be handled using a try-catch block to catch the std::bad_alloc exception, which is the standard mechanism for handling allocation errors in C++. This ensures that the code adheres to C++ best practices and avoids misleading constructs.

Detailed steps:

  1. Remove the null pointer check for timer_ on line 146.
  2. Wrap the allocation of HsaTimer (line 144) in a try-catch block to handle the std::bad_alloc exception.
  3. If an exception is caught, log or handle the error appropriately, such as setting a flag or rethrowing the exception, depending on the desired behavior.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

bgopesh and others added 3 commits July 18, 2025 19:29
…or handling

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ammallya
Copy link
Collaborator

ammallya commented Aug 7, 2025

Imported to ROCm/rocm-systems

@ammallya ammallya closed this Aug 7, 2025
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.

4 participants