fix(cpu): add null check for aligned_alloc in ScratchPadManager (#37369)

Signed-off-by: yassha <50112520+yassha@users.noreply.github.com>
This commit is contained in:
yassha
2026-03-19 10:45:06 +01:00
committed by GitHub
parent ca21483bf9
commit 199f914183

View File

@@ -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;
}
}