bt-api: gatt-client: Fix memory leak 45/101045/1
authorSyam Sidhardhan <s.syam@samsung.com>
Wed, 30 Nov 2016 05:35:55 +0000 (11:05 +0530)
committerSyam Sidhardhan <s.syam@samsung.com>
Wed, 30 Nov 2016 07:05:55 +0000 (23:05 -0800)
[Model]COMMON
[BinType] AP
[Customer]N/A

[Issue#]Memeory leak reported by cppcheck automated tool
[Request]Internal
[Occurrence Version]PK6

[Problem]Memeory leak reported by cppcheck tool
[Cause & Measure]We were no freeing the memory
[Checking Method]Gatt test tool

[Team]BT
[Developer]Syam Sidhardhan <s.syam@samsung.com>
[Solution company] Samsung
[Change Type]N/A

Change-Id: I2002d1f47cc3381a7db442cb72e3880af1a09aac
(cherry picked from commit 24374850100b737a9132c7b02a61955aed97326f)

bt-api/bt-gatt-client.c

index 5e27343..9186ea2 100644 (file)
@@ -158,13 +158,13 @@ BT_EXPORT_API int bluetooth_gatt_set_service_change_watcher(
                        BT_INFO("The watcher is already set");
                        return BLUETOOTH_ERROR_NONE;
                }
-               addr = g_malloc0(sizeof(bluetooth_device_address_t));
-               memcpy(addr, address, sizeof(bluetooth_device_address_t));
 
                if (service_monitor_list == NULL) {
                        BT_ERR("There is NO watcher");
                        return BLUETOOTH_ERROR_NONE;
                }
+               addr = g_malloc0(sizeof(bluetooth_device_address_t));
+               memcpy(addr, address, sizeof(bluetooth_device_address_t));
 
                service_monitor_list =
                        g_slist_append(service_monitor_list, addr);