[enhancement](memory) Support try catch bad alloc (#14135)

This commit is contained in:
Xinyi Zou
2022-11-13 11:22:56 +08:00
committed by GitHub
parent 7682c08af0
commit dd11d5c0a5
33 changed files with 254 additions and 197 deletions

View File

@ -45,8 +45,9 @@ uint8_t* SystemAllocator::allocate_via_malloc(size_t length) {
char buf[64];
auto err = fmt::format("fail to allocate mem via posix_memalign, res={}, errmsg={}.", res,
strerror_r(res, buf, 64));
MemTrackerLimiter::print_log_process_usage(err);
LOG(ERROR) << err;
if (enable_thread_cache_bad_alloc) throw std::bad_alloc {};
MemTrackerLimiter::print_log_process_usage(err);
return nullptr;
}
return (uint8_t*)ptr;