77// ===----------------------------------------------------------------------===//
88
99#include " flang/Runtime/pointer.h"
10+ #include " flang-rt/runtime/allocator-registry.h"
1011#include " flang-rt/runtime/assign-impl.h"
1112#include " flang-rt/runtime/derived.h"
1213#include " flang-rt/runtime/environment.h"
@@ -121,13 +122,15 @@ void RTDEF(PointerAssociateRemapping)(Descriptor &pointer,
121122 }
122123}
123124
124- RT_API_ATTRS void *AllocateValidatedPointerPayload (std::size_t byteSize) {
125+ RT_API_ATTRS void *AllocateValidatedPointerPayload (
126+ std::size_t byteSize, int allocatorIdx) {
125127 // Add space for a footer to validate during deallocation.
126128 constexpr std::size_t align{sizeof (std::uintptr_t )};
127129 byteSize = ((byteSize + align - 1 ) / align) * align;
128130 std::size_t total{byteSize + sizeof (std::uintptr_t )};
129- void *p{std::malloc (total)};
130- if (p) {
131+ AllocFct alloc{allocatorRegistry.GetAllocator (allocatorIdx)};
132+ void *p{alloc (total)};
133+ if (p && allocatorIdx == 0 ) {
131134 // Fill the footer word with the XOR of the ones' complement of
132135 // the base address, which is a value that would be highly unlikely
133136 // to appear accidentally at the right spot.
@@ -151,7 +154,7 @@ int RTDEF(PointerAllocate)(Descriptor &pointer, bool hasStat,
151154 elementBytes = pointer.raw ().elem_len = 0 ;
152155 }
153156 std::size_t byteSize{pointer.Elements () * elementBytes};
154- void *p{AllocateValidatedPointerPayload (byteSize)};
157+ void *p{AllocateValidatedPointerPayload (byteSize, pointer. GetAllocIdx () )};
155158 if (!p) {
156159 return ReturnError (terminator, CFI_ERROR_MEM_ALLOCATION, errMsg, hasStat);
157160 }
@@ -211,6 +214,7 @@ int RTDEF(PointerDeallocate)(Descriptor &pointer, bool hasStat,
211214 return ReturnError (terminator, StatBaseNull, errMsg, hasStat);
212215 }
213216 if (executionEnvironment.checkPointerDeallocation &&
217+ pointer.GetAllocIdx () == kDefaultAllocator &&
214218 !ValidatePointerPayload (pointer.raw ())) {
215219 return ReturnError (terminator, StatBadPointerDeallocation, errMsg, hasStat);
216220 }
0 commit comments