diff --git a/runtime/tests/port/j9vmemTest.c b/runtime/tests/port/j9vmemTest.c index 773ae6cc016..c459645f3bb 100644 --- a/runtime/tests/port/j9vmemTest.c +++ b/runtime/tests/port/j9vmemTest.c @@ -3393,6 +3393,7 @@ j9vmem_testOverlappingSegments(struct J9PortLibrary *portLibrary) struct J9PortVmemIdentifier *vmemID; int *keepCycles; int freed = 0; + int cycleCleanupBound = 0; int i = 0; int j = 0; const char* testName = "j9vmem__testOverlappingSegments"; @@ -3416,6 +3417,9 @@ j9vmem_testOverlappingSegments(struct J9PortLibrary *portLibrary) if (NULL == memPtr) { outputComment(PORTLIB, "Failed to get memory. Error: %s.\n", strerror(errno)); outputComment(PORTLIB, "Ignoring memory allocation failure(%d of %d loops finished).\n", i, CYCLES); + if (0 == i) { + keepCycles[0] = -1; /* This segment would otherwise look like it needed to be freed during cleanup */ + } goto exit; } /* Determine how long to keep the segment */ @@ -3458,7 +3462,8 @@ j9vmem_testOverlappingSegments(struct J9PortLibrary *portLibrary) /* Free remaining segments */ freed = 0; - for (j = 0; j < CYCLES; j++) { + cycleCleanupBound = (CYCLES == i) ? i : i + 1; + for (j = 0; j < cycleCleanupBound; j++) { if (keepCycles[j] >= i) { I_32 rc = j9vmem_free_memory(vmemID[j].address, vmemParams[j].byteAmount, &vmemID[j]); if (0 == rc) {