Server: ConnectionState: Fix thread-safety issue

This commit is contained in:
Tal Aloni 2024-06-01 17:21:15 +03:00
parent cf182e787f
commit 1a8c94ba94
2 changed files with 18 additions and 6 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2014-2019 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2014-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
@ -78,14 +78,20 @@ namespace SMBLibrary.Server
public SMB1Session GetSession(ushort userID) public SMB1Session GetSession(ushort userID)
{ {
SMB1Session session; SMB1Session session;
m_sessions.TryGetValue(userID, out session); lock (m_sessions)
{
m_sessions.TryGetValue(userID, out session);
}
return session; return session;
} }
public void RemoveSession(ushort userID) public void RemoveSession(ushort userID)
{ {
SMB1Session session; SMB1Session session;
m_sessions.TryGetValue(userID, out session); lock (m_sessions)
{
m_sessions.TryGetValue(userID, out session);
}
if (session != null) if (session != null)
{ {
session.Close(); session.Close();

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2014-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2014-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
@ -56,14 +56,20 @@ namespace SMBLibrary.Server
public SMB2Session GetSession(ulong sessionID) public SMB2Session GetSession(ulong sessionID)
{ {
SMB2Session session; SMB2Session session;
m_sessions.TryGetValue(sessionID, out session); lock (m_sessions)
{
m_sessions.TryGetValue(sessionID, out session);
}
return session; return session;
} }
public void RemoveSession(ulong sessionID) public void RemoveSession(ulong sessionID)
{ {
SMB2Session session; SMB2Session session;
m_sessions.TryGetValue(sessionID, out session); lock (m_sessions)
{
m_sessions.TryGetValue(sessionID, out session);
}
if (session != null) if (session != null)
{ {
session.Close(); session.Close();