Update main.cpp

Memory fixes, head_end doesnt get freed and you shouldnt use ->prev pointer after its freed. Also memory leak when payload is selected.
This commit is contained in:
Maniac- 2022-01-15 17:29:33 +02:00 committed by GitHub
parent 6098af25eb
commit 5074c962aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,14 +95,15 @@ extern "C" int _start(int argc, char **argv) {
// Somewhere in this loader is a memory leak.
// This is a hacky solution to free that memory.
uint32_t head_end = (uint32_t) malloc(1024);
MEMExpHeapBlock *curUsedBlock = (MEMExpHeapBlock *) (head_end - 0x14);
MEMExpHeapBlock *prevBlock, *curUsedBlock = (MEMExpHeapBlock *) (head_end - 0x14);
while (curUsedBlock != 0) {
curUsedBlock = curUsedBlock->prev;
prevBlock = curUsedBlock->prev;
free(&curUsedBlock[1]);
if(((uint32_t) &curUsedBlock[1]) == memory_start){
break;
}
curUsedBlock = prevBlock;
}
int res = -1;
@ -256,6 +257,7 @@ std::string PayloadSelectionScreen(const std::map<std::string, std::string> &pay
OSSleepTicks(OSMillisecondsToTicks(16));
}
free(screenBuffer);
int i = 0;
for (auto const&[key, val] : payloads) {
if (i == selected) {
@ -263,6 +265,5 @@ std::string PayloadSelectionScreen(const std::map<std::string, std::string> &pay
}
i++;
}
free(screenBuffer);
return "";
}
}