From: Pawel Wasowski Date: Wed, 16 Sep 2020 14:11:26 +0000 (+0200) Subject: [Bluetooth] Bugfix: prevent memory leak X-Git-Tag: submit/tizen/20200923.101308~7^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c204750493cfed551a9344ad84e5cf006046b516;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Bluetooth] Bugfix: prevent memory leak 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 --- diff --git a/src/bluetooth/bluetooth_gatt_server.cc b/src/bluetooth/bluetooth_gatt_server.cc index e8bdf420..e67d9b34 100644 --- a/src/bluetooth/bluetooth_gatt_server.cc +++ b/src/bluetooth/bluetooth_gatt_server.cc @@ -172,6 +172,7 @@ void BluetoothGATTServer::RegisterService(const picojson::value& args, picojson: */ auto result = InitializeAndCreateHandle(); if (!result) { + BluetoothGATTServerService::DestroyService(0, 0, service_handle, nullptr); result.SetMessage("Couldn't register the service"); ReportError(result, &out); return; @@ -180,6 +181,7 @@ void BluetoothGATTServer::RegisterService(const picojson::value& args, picojson: result = service_.RegisterService(service_handle, this->handle_, new_gatt_objects); if (result.IsError()) { + BluetoothGATTServerService::DestroyService(0, 0, service_handle, nullptr); ReportError(result, &out); return; }