99constexpr std::size_t max_allocations = 20'000 ;
1010void * allocations[max_allocations];
1111void * allocations_array[max_allocations];
12- std::size_t num_allocations = 0u ;
13- std::size_t double_delete = 0u ;
14- bool memory_tracking = false ;
15- bool force_allocation_failure = false ;
12+ std::size_t num_allocations = 0u ;
13+ std::size_t double_delete = 0u ;
14+ bool memory_tracking = false ;
15+ bool force_next_allocation_failure = false ;
1616
1717#define CHECK_MEMORY_LEAKS 1
1818
@@ -22,7 +22,8 @@ void* allocate(std::size_t size, bool array) {
2222 throw std::bad_alloc ();
2323 }
2424
25- if (force_allocation_failure) {
25+ if (force_next_allocation_failure) {
26+ force_next_allocation_failure = false ;
2627 throw std::bad_alloc ();
2728 }
2829
@@ -286,11 +287,10 @@ TEST_CASE("owner acquiring constructor bad alloc", "[owner_construction]") {
286287 {
287288 test_object* raw_ptr = new test_object;
288289 try {
289- force_allocation_failure = true ;
290+ force_next_allocation_failure = true ;
290291 test_ptr{raw_ptr};
291292 } catch (...) {
292293 }
293- force_allocation_failure = false ;
294294 }
295295
296296 REQUIRE (instances == 0 );
@@ -321,11 +321,10 @@ TEST_CASE("owner acquiring constructor with deleter bad alloc", "[owner_construc
321321 {
322322 test_object* raw_ptr = new test_object;
323323 try {
324- force_allocation_failure = true ;
324+ force_next_allocation_failure = true ;
325325 test_ptr_with_deleter{raw_ptr, test_deleter{42 }};
326326 } catch (...) {
327327 }
328- force_allocation_failure = false ;
329328 }
330329
331330 REQUIRE (instances == 0 );
@@ -1325,11 +1324,10 @@ TEST_CASE("owner reset to new bad alloc", "[owner_utility]") {
13251324 test_object* raw_ptr2 = new test_object;
13261325 test_ptr ptr (raw_ptr1);
13271326 try {
1328- force_allocation_failure = true ;
1327+ force_next_allocation_failure = true ;
13291328 ptr.reset (raw_ptr2);
13301329 } catch (...) {
13311330 }
1332- force_allocation_failure = false ;
13331331 REQUIRE (instances == 1 );
13341332 REQUIRE (ptr.get () == raw_ptr1);
13351333 }
@@ -3547,12 +3545,11 @@ TEST_CASE("observer from this maybe no block reset to new bad alloc", "[observer
35473545 test_ptr_from_this_maybe_no_block ptr{raw_ptr1};
35483546
35493547 try {
3550- force_allocation_failure = true ;
3548+ force_next_allocation_failure = true ;
35513549 ptr.reset (raw_ptr2);
35523550 } catch (...) {
35533551 }
35543552
3555- force_allocation_failure = false ;
35563553 REQUIRE (instances == 1 );
35573554 REQUIRE (ptr.get () == raw_ptr1);
35583555 }
0 commit comments