diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-06-13 09:19:38 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-06-13 09:19:38 +0000 |
commit | 30581b966dcf778eeb465f0ea3e2dd42280efdc3 (patch) | |
tree | dbd9a5a687a04a74e15ce69776c1fe02aff07e1b /vespalib | |
parent | 982a3ae1a01cde9844e9bbbbd85865b9d3daa98c (diff) |
Throw if allocation failed.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/alloc.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp index cb9a4b688b3..b8b790254bd 100644 --- a/vespalib/src/vespa/vespalib/util/alloc.cpp +++ b/vespalib/src/vespa/vespalib/util/alloc.cpp @@ -291,7 +291,14 @@ HeapAllocator::alloc(size_t sz) const { PtrAndSize HeapAllocator::salloc(size_t sz) { - return PtrAndSize((sz > 0) ? malloc(sz) : nullptr, sz); + if (sz == 0) { + return PtrAndSize(nullptr, sz); + } + void * ptr = malloc(sz); + if (ptr == nullptr) { + throw IllegalArgumentException(make_string("malloc(%zu) failed with error '%s'", sz, getLastErrorString().c_str())); + } + return PtrAndSize(ptr, sz); } void HeapAllocator::free(PtrAndSize alloc) const { |