Skip to content

Commit 44d12d4

Browse files
committed
Update mallocx() OOM test to deal with smaller hugemax.
Depending on virtual memory resource limits, it is necessary to attempt allocating three maximally sized objects to trigger OOM rather than just two, since the maximum supported size is slightly less than half the total virtual memory address space. This fixes a test failure that was introduced by 0c516a0 (Make *allocx() size class overflow behavior defined.). This resolves jemalloc#379.
1 parent 21e33ed commit 44d12d4

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

test/integration/mallocx.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,27 @@ TEST_END
7070
TEST_BEGIN(test_oom)
7171
{
7272
size_t hugemax, size, alignment;
73-
74-
hugemax = get_huge_size(get_nhuge()-1);
73+
bool oom;
74+
void *ptrs[3];
75+
unsigned i;
7576

7677
/*
77-
* It should be impossible to allocate two objects that each consume
78-
* more than half the virtual address space.
78+
* It should be impossible to allocate three objects that each consume
79+
* nearly half the virtual address space.
7980
*/
80-
{
81-
void *p;
82-
83-
p = mallocx(hugemax, 0);
84-
if (p != NULL) {
85-
assert_ptr_null(mallocx(hugemax, 0),
86-
"Expected OOM for mallocx(size=%#zx, 0)", hugemax);
87-
dallocx(p, 0);
88-
}
81+
hugemax = get_huge_size(get_nhuge()-1);
82+
oom = false;
83+
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
84+
ptrs[i] = mallocx(hugemax, 0);
85+
if (ptrs[i] == NULL)
86+
oom = true;
87+
}
88+
assert_true(oom,
89+
"Expected OOM during series of calls to mallocx(size=%zu, 0)",
90+
hugemax);
91+
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
92+
if (ptrs[i] != NULL)
93+
dallocx(ptrs[i], 0);
8994
}
9095

9196
#if LG_SIZEOF_PTR == 3

0 commit comments

Comments
 (0)