From bff625d069a9f06c9cc71374790976c583a39b6b Mon Sep 17 00:00:00 2001 From: Rikkert01 Date: Sun, 5 Jan 2025 13:46:25 +0100 Subject: [PATCH] [AtModem] Fix NullReferenceException in AtChannel. The _currentCommand and the _currentResponse are used troughout the AtChannel class. They are set to null in the 'finally' of the AtChannel.SendFullCommand. But in very few occasions (once every hour or so) the _currentCommand is used by another thread after it has been set to null, resulting in a NullReferenceException. For example in HandleFinalResponse. This is the same multi-threading problem like the one fixed in PR #1216. We can fix this by placing a lock around the call to AtChannel.ProcessMessage so access to _currentCommand and _currentresponse is mutually exclusive to setting them to null. So NullReference cannot occur. Signed-off-by: Rik Kreeftenberg #1579 --- devices/AtModem/AtParser/AtChannel.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/devices/AtModem/AtParser/AtChannel.cs b/devices/AtModem/AtParser/AtChannel.cs index f0170ce9ab..0ccfa817a8 100644 --- a/devices/AtModem/AtParser/AtChannel.cs +++ b/devices/AtModem/AtParser/AtChannel.cs @@ -409,7 +409,11 @@ private void ReaderLoopAsync() } else { - ProcessMessage(line1); + // lock access to _currentCommand & _currentResponse + lock (_lock) + { + ProcessMessage(line1); + } } } }