diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs index d3a88998f..b7bd3e6da 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs @@ -7,7 +7,7 @@ using System.Threading; namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd { - class BsdContext + class BsdContext : IDisposable { private static readonly ConcurrentDictionary _registry = new(); @@ -158,6 +158,20 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd return LinuxError.SUCCESS; } + public void Dispose() + { + int count; + + lock (_lock) + { + count = _fds.Count; + } + + for (int fd = 0; fd < count; fd++) { + CloseFileDescriptor(fd); + } + } + public static BsdContext GetOrRegister(ulong processId) { BsdContext context = GetContext(processId); @@ -174,12 +188,15 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd public static BsdContext GetContext(ulong processId) { - if (!_registry.TryGetValue(processId, out BsdContext processContext)) - { - return null; - } + return _registry.GetValueOrDefault(processId); + } - return processContext; + public static void DeleteContext(ulong processId) + { + if (_registry.Remove(processId, out BsdContext context)) + { + context.Dispose(); + } } } } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs index fe37ca4fa..f22b1eb14 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs @@ -1165,5 +1165,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd return WriteBsdResult(context, newSockFd, errno); } + + + public override void DestroyAtExit() + { + if (_context != null) { + _context.Dispose(); + } + } } }