Keep track of acquired RPLs and release them on exit

This commit is contained in:
Maschell
2022-10-05 20:08:49 +02:00
parent ea65654607
commit 0e56538cb1
6 changed files with 71 additions and 15 deletions

View File

@@ -1,8 +1,8 @@
#include "utils.h"
#include "globals.h"
#include "logger.h"
#include <algorithm>
#include <coreinit/ios.h>
#include <cstring>
#include <malloc.h>
#include <string>
std::string getPluginPath() {
@@ -69,10 +69,18 @@ OSDynLoad_Error CustomDynLoadAlloc(int32_t size, int32_t align, void **outAddr)
if (!(*outAddr = memalign(align, size))) {
return OS_DYNLOAD_OUT_OF_MEMORY;
}
// keep track of allocated memory to clean it up if RPLs won't get unloaded properly
gAllocatedAddresses.push_back(*outAddr);
return OS_DYNLOAD_OK;
}
void CustomDynLoadFree(void *addr) {
free(addr);
// Remove from list
auto it = std::find(gAllocatedAddresses.begin(), gAllocatedAddresses.end(), addr);
if (it != gAllocatedAddresses.end()) {
gAllocatedAddresses.erase(it);
}
}