plugged a bunch of handle leaks !

This commit is contained in:
smea 2014-10-29 21:26:58 -07:00
parent 08f8caf924
commit 58a1f0c68e
7 changed files with 26 additions and 3 deletions

View File

@ -22,6 +22,8 @@ extern char* fake_heap_end;
static void initArgv();
static u32 heapBase;
void __destroy_handle_list(void);
void __attribute__((noreturn)) __ctru_exit(int rc)
{
// Run the global destructors
@ -35,6 +37,9 @@ void __attribute__((noreturn)) __ctru_exit(int rc)
// Unmap the application heap
svcControlMemory(&heapBase, heapBase, 0x0, __heap_size, MEMOP_FREE, 0x0);
// Close some handles
__destroy_handle_list();
// Jump to the loader if it provided a callback
if (__system_retAddr)
__system_retAddr();

View File

@ -360,7 +360,7 @@ void aptExit()
svcCloseHandle(aptSleepSync);
svcCloseHandle(aptStatusMutex);
//svcCloseHandle(aptLockHandle);
svcCloseHandle(aptLockHandle);
svcCloseHandle(aptStatusEvent);
}

View File

@ -788,7 +788,10 @@ FSFILE_Close(Handle handle)
if((ret = svcSendSyncRequest(handle)))
return ret;
return cmdbuf[1];
ret = cmdbuf[1];
if(!ret)ret = svcCloseHandle(handle);
return ret;
}
/*! Read data from an open file

View File

@ -59,6 +59,7 @@ void gspExitEventHandler()
// Stop event thread
gspRunEvents = false;
svcWaitSynchronization(gspEventThread, 1000000000);
svcCloseHandle(gspEventThread);
// Free events
int i;

View File

@ -48,6 +48,7 @@ cleanup1:
void hidExit()
{
// Unmap HID sharedmem and close handles.
int i; for(i=0; i<5; i++)svcCloseHandle(hidEvents[i]);
svcUnmapMemoryBlock(hidMemHandle, (u32)hidSharedMem);
svcCloseHandle(hidMemHandle);
svcCloseHandle(hidHandle);

View File

@ -45,6 +45,7 @@ cleanup1:
void irrstExit()
{
irrstUsed = false;
svcCloseHandle(irrstEvent);
// Unmap ir:rst sharedmem and close handles.
svcUnmapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem);
svcCloseHandle(irrstMemHandle);

View File

@ -58,6 +58,18 @@ Handle __get_handle_from_list(const char* name) {
return 0;
}
void __destroy_handle_list(void) {
if((u32)__service_ptr == 0)
return;
u32 i, num = __service_ptr->num;
for(i=0; i<num; i++)
svcCloseHandle(__service_ptr->services[i].handle);
__service_ptr->num = 0;
}
Result srvInit()
{
Result rc = 0;