Allow freeing null pointers in the recomp_free export to match the C spec for free (#107)
Some checks failed
validate / windows (x64, Debug) (push) Has been cancelled
validate / windows (x64, Release) (push) Has been cancelled
validate / macos (arm64, Debug) (push) Has been cancelled
validate / macos (arm64, Release) (push) Has been cancelled
validate / macos (x64, Debug) (push) Has been cancelled
validate / macos (x64, Release) (push) Has been cancelled
validate / ubuntu (arm64, Debug) (push) Has been cancelled
validate / ubuntu (arm64, Release) (push) Has been cancelled
validate / ubuntu (x64, Debug) (push) Has been cancelled
validate / ubuntu (x64, Release) (push) Has been cancelled

This commit is contained in:
Wiseguy 2025-04-13 22:09:15 -04:00 committed by GitHub
parent 3c49f87ac6
commit 4b57f50722
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@
#include "librecomp/addresses.hpp"
#include "librecomp/overlays.hpp"
#include "librecomp/helpers.hpp"
static uint32_t heap_offset;
@ -15,7 +16,12 @@ extern "C" void recomp_alloc(uint8_t* rdram, recomp_context* ctx) {
}
extern "C" void recomp_free(uint8_t* rdram, recomp_context* ctx) {
recomp::free(rdram, TO_PTR(void, ctx->r4));
PTR(void) to_free = _arg<0, PTR(void)>(rdram, ctx);
// Handle NULL frees.
if (to_free == NULLPTR) {
return;
}
recomp::free(rdram, TO_PTR(void, to_free));
}
void recomp::register_heap_exports() {