mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-04 10:32: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();
|
Result nifmInitialize();
|
||||||
void nifmExit(void);
|
void nifmExit(void);
|
||||||
|
|
||||||
Result CreateGeneralService(IGeneralService*out);
|
|
||||||
Result _CreateGeneralService(IGeneralService* out, u64 in);
|
Result _CreateGeneralService(IGeneralService* out, u64 in);
|
||||||
Result _CreateGeneralServiceOld(IGeneralService* out);
|
Result _CreateGeneralServiceOld(IGeneralService* out);
|
||||||
|
|
||||||
Result GetCurrentIpAddress(IGeneralService* srv, u32* out);
|
Result GetCurrentIpAddress(u32* out);
|
@ -1584,15 +1584,10 @@ cleanup:
|
|||||||
|
|
||||||
long gethostid(void) {
|
long gethostid(void) {
|
||||||
Result rc;
|
Result rc;
|
||||||
IGeneralService igs;
|
|
||||||
rc = CreateGeneralService(&igs);
|
|
||||||
if(R_SUCCEEDED(rc)){
|
|
||||||
u32 id;
|
u32 id;
|
||||||
rc = GetCurrentIpAddress(&igs, &id);
|
rc = GetCurrentIpAddress(&id);
|
||||||
if(R_SUCCEEDED(rc)){
|
if(R_SUCCEEDED(rc))
|
||||||
return id;
|
return id;
|
||||||
}
|
|
||||||
}
|
|
||||||
return INADDR_LOOPBACK;
|
return INADDR_LOOPBACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,24 +7,35 @@
|
|||||||
#include "services/nifm.h"
|
#include "services/nifm.h"
|
||||||
|
|
||||||
static Service g_nifmSrv;
|
static Service g_nifmSrv;
|
||||||
|
static IGeneralService g_nifmIGS;
|
||||||
|
|
||||||
Result nifmInitialize(){
|
Result nifmInitialize(){
|
||||||
if (serviceIsActive(&g_nifmSrv))
|
if (serviceIsActive(&g_nifmSrv))
|
||||||
return 0;
|
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){
|
void nifmExit(void){
|
||||||
|
if(serviceIsActive(&g_nifmIGS.s))
|
||||||
|
serviceClose(&g_nifmIGS.s);
|
||||||
|
if(serviceIsActive(&g_nifmSrv))
|
||||||
serviceClose(&g_nifmSrv);
|
serviceClose(&g_nifmSrv);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result CreateGeneralService(IGeneralService *out){
|
|
||||||
if(kernelAbove200())
|
|
||||||
return _CreateGeneralService(out, 0); // What does this parameter do?
|
|
||||||
else
|
|
||||||
return _CreateGeneralServiceOld(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result _CreateGeneralService(IGeneralService* out, u64 in){
|
Result _CreateGeneralService(IGeneralService* out, u64 in){
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
ipcInitialize(&c);
|
ipcInitialize(&c);
|
||||||
@ -55,10 +66,9 @@ Result _CreateGeneralService(IGeneralService* out, u64 in){
|
|||||||
|
|
||||||
rc = resp->result;
|
rc = resp->result;
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc))
|
||||||
serviceCreate(&out->s, r.Handles[0]);
|
serviceCreate(&out->s, r.Handles[0]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -98,7 +108,7 @@ Result _CreateGeneralServiceOld(IGeneralService* out){
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetCurrentIpAddress(IGeneralService* srv, u32* out){
|
Result GetCurrentIpAddress(u32* out){
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
ipcInitialize(&c);
|
ipcInitialize(&c);
|
||||||
|
|
||||||
@ -112,7 +122,7 @@ Result GetCurrentIpAddress(IGeneralService* srv, u32* out){
|
|||||||
raw->magic = SFCI_MAGIC;
|
raw->magic = SFCI_MAGIC;
|
||||||
raw->cmd_id = 12;
|
raw->cmd_id = 12;
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&srv->s);
|
Result rc = serviceIpcDispatch(&g_nifmIGS.s);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user