From 199f914183e1f50f0a63a7fa0dd9b025952d8689 Mon Sep 17 00:00:00 2001 From: yassha <50112520+yassha@users.noreply.github.com> Date: Thu, 19 Mar 2026 10:45:06 +0100 Subject: [PATCH] fix(cpu): add null check for aligned_alloc in ScratchPadManager (#37369) Signed-off-by: yassha <50112520+yassha@users.noreply.github.com> --- csrc/cpu/utils.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/csrc/cpu/utils.cpp b/csrc/cpu/utils.cpp index f2085b73b6..e2812fe57a 100644 --- a/csrc/cpu/utils.cpp +++ b/csrc/cpu/utils.cpp @@ -173,10 +173,13 @@ ScratchPadManager::ScratchPadManager() : size_(0), ptr_(nullptr) { void ScratchPadManager::realloc(size_t new_size) { new_size = round(new_size); if (new_size > size_) { + void* new_ptr = std::aligned_alloc(64, new_size); + TORCH_CHECK(new_ptr != nullptr, + "ScratchPadManager: aligned_alloc failed for size ", new_size); if (ptr_ != nullptr) { std::free(ptr_); } - ptr_ = std::aligned_alloc(64, new_size); + ptr_ = new_ptr; size_ = new_size; } }