MCPcopy Create free account
hub / github.com/beefytech/Beef / handleOOM

Function handleOOM

BeefRT/JEMalloc/src/jemalloc_cpp.cpp:56–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54#endif
55
56JEMALLOC_NOINLINE
57static void *
58handleOOM(std::size_t size, bool nothrow) {
59 if (opt_experimental_infallible_new) {
60 safety_check_fail("<jemalloc>: Allocation failed and "
61 "opt.experimental_infallible_new is true. Aborting.\n");
62 return nullptr;
63 }
64
65 void *ptr = nullptr;
66
67 while (ptr == nullptr) {
68 std::new_handler handler;
69 // GCC-4.8 and clang 4.0 do not have std::get_new_handler.
70 {
71 static std::mutex mtx;
72 std::lock_guard<std::mutex> lock(mtx);
73
74 handler = std::set_new_handler(nullptr);
75 std::set_new_handler(handler);
76 }
77 if (handler == nullptr)
78 break;
79
80 try {
81 handler();
82 } catch (const std::bad_alloc &) {
83 break;
84 }
85
86 ptr = je_malloc(size);
87 }
88
89 if (ptr == nullptr && !nothrow)
90 std::__throw_bad_alloc();
91 return ptr;
92}
93
94template <bool IsNoExcept>
95JEMALLOC_NOINLINE

Callers 2

fallback_implFunction · 0.85
alignedNewImplFunction · 0.85

Calls 1

safety_check_failFunction · 0.85

Tested by

no test coverage detected