From: Pawel Andruszkiewicz Date: Wed, 3 Jun 2015 13:58:03 +0000 (+0200) Subject: [Bluetooth] Fixed handling of allocated data. X-Git-Tag: submit/tizen_mobile/20150612.133019^2~2^2~44^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c6c3f63289757cfd601698cf80ee32dfe5380ac4;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Bluetooth] Fixed handling of allocated data. Prevent CID: 386129 [Verification] Code compiles. Change-Id: I89c39a636d4fc0b0299387441fe0889d81fc8f84 Signed-off-by: Pawel Andruszkiewicz --- diff --git a/src/bluetooth/bluetooth_gatt_service.cc b/src/bluetooth/bluetooth_gatt_service.cc index 5f79f742..53c2594a 100755 --- a/src/bluetooth/bluetooth_gatt_service.cc +++ b/src/bluetooth/bluetooth_gatt_service.cc @@ -397,11 +397,10 @@ void BluetoothGATTService::WriteValue(const picojson::value& args, BluetoothGATTService* service; }; - Data* user_data = new Data{callback_handle, this}; bt_gatt_h handle = (bt_gatt_h) static_cast(args.get("handle").get()); auto write_value = [](int result, bt_gatt_h handle, void *user_data) -> void { - Data* data = (Data*) user_data; + Data* data = static_cast(user_data); double callback_handle = data->callback_handle; BluetoothGATTService* service = data->service; delete data; @@ -424,10 +423,10 @@ void BluetoothGATTService::WriteValue(const picojson::value& args, }, response); }; - int ret = bt_gatt_set_value(handle, value_data.get(), value_size); + if (BT_ERROR_NONE != ret) { - LOGE("Couldn't set value"); + LoggerE("Couldn't set value"); std::shared_ptr response = std::shared_ptr(new picojson::value(picojson::object())); ReportError(util::GetBluetoothError(ret, "Failed to set value"), @@ -437,9 +436,11 @@ void BluetoothGATTService::WriteValue(const picojson::value& args, instance_.SyncResponse(callback_handle, response); }, response); } else { - ret = bt_gatt_client_write_value(handle, write_value, (void*)user_data); + Data* user_data = new Data{callback_handle, this}; + ret = bt_gatt_client_write_value(handle, write_value, user_data); if (BT_ERROR_NONE != ret) { - LOGE("Couldn't register callback for write value"); + delete user_data; + LoggerE("Couldn't register callback for write value"); } } ReportSuccess(out);