summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-06-13 09:19:38 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-06-13 09:19:38 +0000
commit30581b966dcf778eeb465f0ea3e2dd42280efdc3 (patch)
treedbd9a5a687a04a74e15ce69776c1fe02aff07e1b /vespalib
parent982a3ae1a01cde9844e9bbbbd85865b9d3daa98c (diff)
Throw if allocation failed.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.cpp9
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 {