diff --git a/cpp11/zone.hpp b/cpp11/zone.hpp index c86a3304..a5635450 100644 --- a/cpp11/zone.hpp +++ b/cpp11/zone.hpp @@ -230,8 +230,13 @@ inline void* zone::allocate_expand(size_t size) } chunk* c = static_cast(::malloc(sizeof(chunk) + sz)); + if (!c) return nullptr; char* ptr = reinterpret_cast(c) + sizeof(chunk); + if (!ptr) { + ::free(c); + return nullptr; + } c->next_ = cl->head_; cl->head_ = c;