From f0e187c3fd26da57405018afad6e7a09aa013c38 Mon Sep 17 00:00:00 2001 From: X512 Date: Wed, 30 Nov 2022 20:16:30 +0900 Subject: [PATCH] kernel: follow-up to hrev56619: use new(std::nothrow) to handle allocation failures. Change-Id: I15d84b24dcea17741382b1d5285acf6219a39811 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5868 Reviewed-by: waddlesplash Tested-by: Commit checker robot --- src/system/kernel/device_manager/legacy_drivers.cpp | 4 ++-- src/system/kernel/low_resource_manager.cpp | 2 +- src/system/kernel/vm/VMAnonymousCache.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/system/kernel/device_manager/legacy_drivers.cpp b/src/system/kernel/device_manager/legacy_drivers.cpp index d598d50256..fc74d40db7 100644 --- a/src/system/kernel/device_manager/legacy_drivers.cpp +++ b/src/system/kernel/device_manager/legacy_drivers.cpp @@ -1133,7 +1133,7 @@ start_watching(const char* base, const char* sub) static struct driver_entry* new_driver_entry(const char* path, dev_t device, ino_t node) { - driver_entry* entry = new driver_entry; + driver_entry* entry = new(std::nothrow) driver_entry; if (entry == NULL) return NULL; @@ -1519,7 +1519,7 @@ legacy_driver_probe(const char* subPath) extern "C" status_t legacy_driver_init(void) { - sDriverHash = new DriverTable(); + sDriverHash = new(std::nothrow) DriverTable(); if (sDriverHash == NULL || sDriverHash->Init(DRIVER_HASH_SIZE) != B_OK) return B_NO_MEMORY; diff --git a/src/system/kernel/low_resource_manager.cpp b/src/system/kernel/low_resource_manager.cpp index f1f160da43..cee6cb764e 100644 --- a/src/system/kernel/low_resource_manager.cpp +++ b/src/system/kernel/low_resource_manager.cpp @@ -468,7 +468,7 @@ register_low_resource_handler(low_resource_func function, void* data, TRACE(("register_low_resource_handler(function = %p, data = %p)\n", function, data)); - low_resource_handler *newHandler = new low_resource_handler; + low_resource_handler *newHandler = new(std::nothrow) low_resource_handler; if (newHandler == NULL) return B_NO_MEMORY; diff --git a/src/system/kernel/vm/VMAnonymousCache.cpp b/src/system/kernel/vm/VMAnonymousCache.cpp index 6b7a7f1243..6f94fcfc9f 100644 --- a/src/system/kernel/vm/VMAnonymousCache.cpp +++ b/src/system/kernel/vm/VMAnonymousCache.cpp @@ -1454,7 +1454,7 @@ swap_file_add(const char* path) } // do the allocations and prepare the swap_file structure - swap_file* swap = new swap_file; + swap_file* swap = new(std::nothrow) swap_file; if (swap == NULL) { close(fd); return B_NO_MEMORY;