From b8627563a0be413ba296158c8014fe1308858008 Mon Sep 17 00:00:00 2001 From: Aaron Yu Date: Thu, 9 Feb 2023 13:03:33 -0800 Subject: [PATCH] Fix bluetooth socket crash during release of resource From the crash call stack, the app crashed at the line `windows_socket = nullptr;` This is because the previous line `windows_socket_.Close();` has already released all unmanaged resources associated with the StreamSocket object. https://learn.microsoft.com/en-us/uwp/api/windows.networking.sockets.streamsocket.close?view=winrt-22621#remarks By RAII, assigning `windows_socket_` to nullptr is equivalent to calling `delete` on the StreamSocket allocated on the heap again, which results in null pointer exception `Exception infoEXCEPTION_ACCESS_VIOLATION_READ @0x00000000` because it has already been released in the previous line by Close(). PiperOrigin-RevId: 508454142 --- .../platform/implementation/windows/bluetooth_classic_socket.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/platform/implementation/windows/bluetooth_classic_socket.cc b/internal/platform/implementation/windows/bluetooth_classic_socket.cc index d12401ec..5388075d 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_socket.cc +++ b/internal/platform/implementation/windows/bluetooth_classic_socket.cc @@ -89,7 +89,6 @@ Exception BluetoothSocket::Close() { try { if (windows_socket_ != nullptr) { windows_socket_.Close(); - windows_socket_ = nullptr; } return {Exception::kSuccess}; } catch (std::exception exception) {