Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid segfaults in j9vmem_testOverlappingSegments #19517

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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