diff --git a/runtime/executor/tensor_parser_exec_aten.cpp b/runtime/executor/tensor_parser_exec_aten.cpp index 5267a089d60..31ec2377f16 100644 --- a/runtime/executor/tensor_parser_exec_aten.cpp +++ b/runtime/executor/tensor_parser_exec_aten.cpp @@ -41,6 +41,10 @@ ET_NODISCARD Result getMemPlannedPtr( const executorch_flatbuffer::AllocationDetails* allocation_info, size_t nbytes, HierarchicalAllocator* allocator) { + ET_CHECK_OR_RETURN_ERROR( + allocator != nullptr, + InvalidState, + "HierarchicalAllocator must not be null for memory-planned tensor"); // Normal non-constant Tensor. Allocate data using mem_id and offset. // TODO(T142455629): make the allocator actually id based and not indexed @@ -189,6 +193,13 @@ ET_NODISCARD Result getTensorDataPtr( const executorch_flatbuffer::AllocationDetails* allocation_info = s_tensor->allocation_info(); + if (allocation_info != nullptr) { + ET_CHECK_OR_RETURN_ERROR( + allocator != nullptr, + InvalidState, + "HierarchicalAllocator is null but tensor has allocation_info requiring memory-planned buffers"); + } + // External tensors. if (s_tensor->extra_tensor_info() != nullptr && s_tensor->extra_tensor_info()->location() ==