From 9221d12ae18401b59fa6054f59e100c13bc849e9 Mon Sep 17 00:00:00 2001 From: jfcarroll Date: Tue, 9 Nov 2021 11:44:49 -0800 Subject: [PATCH] This fixes a crash when calling StopAdvertising PiperOrigin-RevId: 408665191 --- .../impl/windows/bluetooth_classic_server_socket.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpp/platform/impl/windows/bluetooth_classic_server_socket.cc b/cpp/platform/impl/windows/bluetooth_classic_server_socket.cc index d676cf16..daff43e5 100644 --- a/cpp/platform/impl/windows/bluetooth_classic_server_socket.cc +++ b/cpp/platform/impl/windows/bluetooth_classic_server_socket.cc @@ -179,9 +179,14 @@ void BluetoothServerSocket::InitializeServiceSdpAttributes( // Returns Exception::kIo on error, Exception::kSuccess otherwise. Exception BluetoothServerSocket::Close() { EnterCriticalSection(&critical_section_); + if (closed_) { + LeaveCriticalSection(&critical_section_); + return {Exception::kSuccess}; + } + + rfcomm_provider_.StopAdvertising(); closed_ = true; bluetooth_sockets_ = {}; - rfcomm_provider_.StopAdvertising(); LeaveCriticalSection(&critical_section_); return {Exception::kSuccess};