Skip to content

SUNMemory allocation failure does not null out the caller output pointer #5041

@WeiqunZhang

Description

@WeiqunZhang
  • Type: Correctness
  • Severity: Medium
  • Component: SUNDIALS memory helper alloc callback
  • Location:
    • Src/Extern/SUNDIALS/AMReX_SUNMemory.cpp:59

Problem

In Alloc, on arena failure the code assigns memptr = nullptr instead of *memptr = nullptr.

memptr = nullptr;

This only changes the local parameter and leaves caller-visible output unchanged.

Impact

  • Caller may observe stale/uninitialized output pointer on failure.
  • Can trigger later invalid memory use paths.

Suggested patch

Set the pointee, not the local parameter variable.

--- a/Src/Extern/SUNDIALS/AMReX_SUNMemory.cpp
+++ b/Src/Extern/SUNDIALS/AMReX_SUNMemory.cpp
@@
-            memptr = nullptr;
+            *memptr = nullptr;
             return -1;

Prepared by Codex

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions