diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-06-13 13:19:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 13:19:14 +0200 |
commit | 540970f8d0a2b5d9c773f8d97e2970bfaffb5f08 (patch) | |
tree | cce88c38a1e62740f458f95a846ce06072529d63 /vespalib | |
parent | 3f24e1665dc1ec44259bb3fbb85ad38fb015311c (diff) | |
parent | 58b7e28b4a57b990a17b495a6a9161641826c6c5 (diff) |
Merge pull request #27403 from vespa-engine/balder/throw-on-failed-malloc
Throw if allocation failed.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/alloc.cpp | 9 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/exceptions.cpp | 4 |
2 files changed, 10 insertions, 3 deletions
diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp index cb9a4b688b3..4e04dd20d91 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 OOMException(make_string("malloc(%zu) failed with error '%s'", sz, getLastErrorString().c_str())); + } + return PtrAndSize(ptr, sz); } void HeapAllocator::free(PtrAndSize alloc) const { diff --git a/vespalib/src/vespa/vespalib/util/exceptions.cpp b/vespalib/src/vespa/vespalib/util/exceptions.cpp index 5bb85d1e275..45f63bf56fa 100644 --- a/vespalib/src/vespa/vespalib/util/exceptions.cpp +++ b/vespalib/src/vespa/vespalib/util/exceptions.cpp @@ -55,8 +55,8 @@ ExceptionWithPayload::ExceptionWithPayload(ExceptionWithPayload &&) noexcept = d ExceptionWithPayload & ExceptionWithPayload::operator = (ExceptionWithPayload &&) noexcept = default; ExceptionWithPayload::~ExceptionWithPayload() = default; -SilenceUncaughtException::SilenceUncaughtException(const std::exception & e) : - _oldTerminate(std::set_terminate(silent_terminate)) +SilenceUncaughtException::SilenceUncaughtException(const std::exception & e) + : _oldTerminate(std::set_terminate(silent_terminate)) { std::lock_guard<std::mutex> guard(_G_silence_mutex); _G_what = e.what(); |