Skip to content

Commit

Permalink
Merge pull request #18966 from hrydgard/fix-sceheap-memleak
Browse files Browse the repository at this point in the history
Fix memory leak on shutdown in sceHeap
  • Loading branch information
hrydgard committed Apr 2, 2024
2 parents 30a809d + 971320c commit 744678b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Core/HLE/sceHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ struct Heap {
static std::map<u32, Heap *> heapList;

static Heap *getHeap(u32 addr) {
auto found = heapList.find(addr);
if (found == heapList.end()) {
return NULL;
auto it = heapList.find(addr);
if (it == heapList.end()) {
return nullptr;
}
return found->second;
return it->second;
}

void __HeapDoState(PointerWrap &p) {
Expand All @@ -73,6 +73,13 @@ void __HeapInit() {
heapList.clear();
}

void __HeapShutdown() {
for (auto it : heapList) {
delete it.second;
}
heapList.clear();
}

static int sceHeapReallocHeapMemory(u32 heapAddr, u32 memPtr, int memSize) {
ERROR_LOG_REPORT(HLE,"UNIMPL sceHeapReallocHeapMemory(%08x, %08x, %08x)", heapAddr, memPtr, memSize);
return 0;
Expand Down
4 changes: 3 additions & 1 deletion Core/HLE/sceHeap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
#pragma once

void Register_sceHeap();

void __HeapInit();
void __HeapDoState(PointerWrap &p);
void __HeapShutdown();
void __HeapDoState(PointerWrap &p);
1 change: 1 addition & 0 deletions Core/HLE/sceKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ void __KernelShutdown()
__AtracShutdown();
__AudioShutdown();
__IoShutdown();
__HeapShutdown();
__KernelMutexShutdown();
__KernelThreadingShutdown();
__KernelMemoryShutdown();
Expand Down

0 comments on commit 744678b

Please sign in to comment.