mirror of
https://github.com/wiiu-env/WUMSLoader.git
synced 2024-11-14 04:05:08 +01:00
Memset every buffer allocated on the default heap before freeing
This commit is contained in:
parent
f7f8b007fa
commit
1f7d853d65
@ -1,4 +1,5 @@
|
||||
#include "utils/logger.h"
|
||||
#include "utils/utils.h"
|
||||
#include <coreinit/memdefaultheap.h>
|
||||
#include <cstdint>
|
||||
#include <fcntl.h>
|
||||
@ -6,9 +7,6 @@
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
#define ROUNDDOWN(val, align) ((val) & ~(align - 1))
|
||||
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)
|
||||
|
||||
int32_t LoadFileToMem(const std::string &filepath, uint8_t **inbuffer, uint32_t *size) {
|
||||
//! always initialze input
|
||||
*inbuffer = nullptr;
|
||||
@ -47,6 +45,7 @@ int32_t LoadFileToMem(const std::string &filepath, uint8_t **inbuffer, uint32_t
|
||||
::close(iFd);
|
||||
|
||||
if (done != filesize) {
|
||||
memset(buffer, 0, ROUNDUP(filesize, 0x40));
|
||||
free(buffer);
|
||||
buffer = nullptr;
|
||||
return -3;
|
||||
|
@ -45,7 +45,12 @@ std::optional<std::shared_ptr<ModuleData>> ModuleDataFactory::load(const std::st
|
||||
return {};
|
||||
}
|
||||
|
||||
auto cleanupBuffer = onLeavingScope([buffer]() { MEMFreeToDefaultHeap(buffer); });
|
||||
auto cleanupBuffer = onLeavingScope([buffer, fsize]() {
|
||||
// Some games (e.g. Minecraft) expect the default heap to be empty.
|
||||
// Make sure to clean up the memory after using it
|
||||
memset(buffer, 0, ROUNDUP(fsize, 0x40));
|
||||
MEMFreeToDefaultHeap(buffer);
|
||||
});
|
||||
|
||||
// Load ELF data
|
||||
if (!reader.load(reinterpret_cast<char *>(buffer), fsize)) {
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#define ROUNDDOWN(val, align) ((val) & ~(align - 1))
|
||||
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)
|
||||
|
||||
template<class T, class... Args>
|
||||
std::unique_ptr<T> make_unique_nothrow(Args &&...args) noexcept(noexcept(T(std::forward<Args>(args)...))) {
|
||||
|
Loading…
Reference in New Issue
Block a user