In the previous implementation if a service was successfully created,
but its registration failed, the resources associated with its handle
were not released.
Such a situation has occurred when Bluetooth was disabled and
BluetoothGATTServer::registerService() was called.
This commit adds the missing line that destroys the handle.
[Verification] The code compiles.
Tested in chrome console - server is successfully created and reports
errors in case of disabled bluetooth adapter. No crash or other issues observed.
Change-Id: I85741e51638abd6b5443d7f7ce5d84e9279fc498
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
*/
auto result = InitializeAndCreateHandle();
if (!result) {
+ BluetoothGATTServerService::DestroyService(0, 0, service_handle, nullptr);
result.SetMessage("Couldn't register the service");
ReportError(result, &out);
return;
result = service_.RegisterService(service_handle, this->handle_, new_gatt_objects);
if (result.IsError()) {
+ BluetoothGATTServerService::DestroyService(0, 0, service_handle, nullptr);
ReportError(result, &out);
return;
}