]> Chaos Git - corbenik/ctrulib.git/commitdiff
plugged a bunch of handle leaks !
authorsmea <smealum@gmail.com>
Thu, 30 Oct 2014 04:26:58 +0000 (21:26 -0700)
committersmea <smealum@gmail.com>
Thu, 30 Oct 2014 04:26:58 +0000 (21:26 -0700)
libctru/source/initSystem.c
libctru/source/services/apt.c
libctru/source/services/fs.c
libctru/source/services/gsp.c
libctru/source/services/hid.c
libctru/source/services/irrst.c
libctru/source/srv.c

index 57ef26da6aadee4cbdcf308c9ba2ab087b7c09c6..b4945673099a2a6385f39bc323b62daed4e0ca4d 100644 (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();
index 8c4c6ec621653a3abb6f773087317dd76f7182e2..3b995a856274b9d24285caa5f186d308f1e84eb6 100644 (file)
@@ -360,7 +360,7 @@ void aptExit()
        svcCloseHandle(aptSleepSync);
 
        svcCloseHandle(aptStatusMutex);
-       //svcCloseHandle(aptLockHandle);
+       svcCloseHandle(aptLockHandle);
        svcCloseHandle(aptStatusEvent);
 }
 
index 00a184b623b3a61f0bc36decc19cff462c6d959d..47946f873c43d910b83c727e710e41258d16ba90 100644 (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
index 24fff1dbdb966d181407b509eb10dd965f26e871..514a7450b50b1c2b02f94a9b784df47f71b0be51 100644 (file)
@@ -59,6 +59,7 @@ void gspExitEventHandler()
        // Stop event thread
        gspRunEvents = false;
        svcWaitSynchronization(gspEventThread, 1000000000);
+       svcCloseHandle(gspEventThread);
 
        // Free events
        int i;
index eb14c5da1e4c4d14a29751aee8c5062fd661bc7d..cc17b688414ea76f9b5794422ab3a955768f303e 100644 (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);
index f00aaa23430db397115619c5e1efa513cae4af08..87121ac277a567ef121a8916c7d0245b8e697881 100644 (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);
index 257b58551201f2579e71f4964d32c32f64a9fb32..ad6e5101453b473dd048564628b14c5a210ea548 100644 (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;
@@ -163,4 +175,4 @@ Result srvUnregisterProcess(u32 procid)
        if((rc = svcSendSyncRequest(g_srv_handle))) return rc;
                
        return cmdbuf[1];
-}
\ No newline at end of file
+}