mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-04 02:22:15 +02:00
Fixed IGeneralService leak
IGeneralService is now cached, removing the necessity for it to be closed by user (as long as they close nifm)
This commit is contained in:
parent
23da34056c
commit
b99729142b
@ -19,8 +19,7 @@ typedef struct {
|
||||
Result nifmInitialize();
|
||||
void nifmExit(void);
|
||||
|
||||
Result CreateGeneralService(IGeneralService*out);
|
||||
Result _CreateGeneralService(IGeneralService* out, u64 in);
|
||||
Result _CreateGeneralServiceOld(IGeneralService* out);
|
||||
|
||||
Result GetCurrentIpAddress(IGeneralService* srv, u32* out);
|
||||
Result GetCurrentIpAddress(u32* out);
|
@ -1584,15 +1584,10 @@ cleanup:
|
||||
|
||||
long gethostid(void) {
|
||||
Result rc;
|
||||
IGeneralService igs;
|
||||
rc = CreateGeneralService(&igs);
|
||||
if(R_SUCCEEDED(rc)){
|
||||
u32 id;
|
||||
rc = GetCurrentIpAddress(&igs, &id);
|
||||
if(R_SUCCEEDED(rc)){
|
||||
return id;
|
||||
}
|
||||
}
|
||||
u32 id;
|
||||
rc = GetCurrentIpAddress(&id);
|
||||
if(R_SUCCEEDED(rc))
|
||||
return id;
|
||||
return INADDR_LOOPBACK;
|
||||
}
|
||||
|
||||
|
@ -7,33 +7,44 @@
|
||||
#include "services/nifm.h"
|
||||
|
||||
static Service g_nifmSrv;
|
||||
static IGeneralService g_nifmIGS;
|
||||
|
||||
Result nifmInitialize(){
|
||||
if (serviceIsActive(&g_nifmSrv))
|
||||
return 0;
|
||||
return smGetService(&g_nifmSrv, "nifm:u");
|
||||
Result rc;
|
||||
|
||||
rc = smGetService(&g_nifmSrv, "nifm:u");
|
||||
|
||||
if(R_SUCCEEDED(rc)){
|
||||
if(kernelAbove200())
|
||||
rc = _CreateGeneralService(&g_nifmIGS, 0); // What does this parameter do?
|
||||
else
|
||||
rc = _CreateGeneralServiceOld(&g_nifmIGS);
|
||||
}
|
||||
|
||||
if(R_FAILED(rc))
|
||||
nifmExit();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void nifmExit(void){
|
||||
serviceClose(&g_nifmSrv);
|
||||
}
|
||||
|
||||
Result CreateGeneralService(IGeneralService *out){
|
||||
if(kernelAbove200())
|
||||
return _CreateGeneralService(out, 0); // What does this parameter do?
|
||||
else
|
||||
return _CreateGeneralServiceOld(out);
|
||||
if(serviceIsActive(&g_nifmIGS.s))
|
||||
serviceClose(&g_nifmIGS.s);
|
||||
if(serviceIsActive(&g_nifmSrv))
|
||||
serviceClose(&g_nifmSrv);
|
||||
}
|
||||
|
||||
Result _CreateGeneralService(IGeneralService* out, u64 in){
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 param;
|
||||
u64 param;
|
||||
} PACKED *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
@ -55,9 +66,8 @@ Result _CreateGeneralService(IGeneralService* out, u64 in){
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
serviceCreate(&out->s, r.Handles[0]);
|
||||
}
|
||||
if (R_SUCCEEDED(rc))
|
||||
serviceCreate(&out->s, r.Handles[0]);
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -98,7 +108,7 @@ Result _CreateGeneralServiceOld(IGeneralService* out){
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result GetCurrentIpAddress(IGeneralService* srv, u32* out){
|
||||
Result GetCurrentIpAddress(u32* out){
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
@ -112,7 +122,7 @@ Result GetCurrentIpAddress(IGeneralService* srv, u32* out){
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 12;
|
||||
|
||||
Result rc = serviceIpcDispatch(&srv->s);
|
||||
Result rc = serviceIpcDispatch(&g_nifmIGS.s);
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user