Skip to content

Commit

Permalink
Merge pull request #19517 from cjjdespres/fix-overlapping-segment-test
Browse files Browse the repository at this point in the history
Avoid segfaults in j9vmem_testOverlappingSegments
  • Loading branch information
mpirvu authored Jan 8, 2025
2 parents f122827 + 1a608bf commit 7fb956b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion runtime/tests/port/j9vmemTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 */
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7fb956b

Please sign in to comment.