This fixes a crash when calling StopAdvertising

PiperOrigin-RevId: 408665191
This commit is contained in:
jfcarroll
2021-11-09 11:45:31 -08:00
committed by Copybara-Service
parent dd237591f9
commit 9221d12ae1
@@ -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};