From 54deded929203a64555d97424d5bb4b884fff69f Mon Sep 17 00:00:00 2001 From: gdkchan Date: Thu, 5 May 2022 14:58:59 -0300 Subject: Fix shared memory leak on Windows (#3319) * Fix shared memory leak on Windows * Fix memory leak caused by RO session disposal not decrementing the memory manager ref count * Fix UnmapViewInternal deadlock * Was not supposed to add those back --- Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Ryujinx.HLE/HOS') diff --git a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs index 0ce65e3a..d986bc41 100644 --- a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs +++ b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs @@ -30,6 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro private List _nroInfos; private KProcess _owner; + private IVirtualMemoryManager _ownerMm; private static Random _random = new Random(); @@ -38,6 +39,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro _nrrInfos = new List(MaxNrr); _nroInfos = new List(MaxNro); _owner = null; + _ownerMm = null; } private ResultCode ParseNrr(out NrrInfo nrrInfo, ServiceCtx context, ulong nrrAddress, ulong nrrSize) @@ -564,10 +566,12 @@ namespace Ryujinx.HLE.HOS.Services.Ro return ResultCode.InvalidSession; } - _owner = context.Process.HandleTable.GetKProcess(context.Request.HandleDesc.ToCopy[0]); - context.Device.System.KernelContext.Syscall.CloseHandle(context.Request.HandleDesc.ToCopy[0]); + int processHandle = context.Request.HandleDesc.ToCopy[0]; + _owner = context.Process.HandleTable.GetKProcess(processHandle); + _ownerMm = _owner?.CpuMemory; + context.Device.System.KernelContext.Syscall.CloseHandle(processHandle); - if (_owner?.CpuMemory is IRefCounted rc) + if (_ownerMm is IRefCounted rc) { rc.IncrementReferenceCount(); } @@ -586,7 +590,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro _nroInfos.Clear(); - if (_owner?.CpuMemory is IRefCounted rc) + if (_ownerMm is IRefCounted rc) { rc.DecrementReferenceCount(); } -- cgit v1.2.3