From: Syam Sidhardhan Date: Wed, 31 May 2017 07:31:48 +0000 (+0530) Subject: gatt: Fix mismatching allocation and deallocation X-Git-Tag: submit/tizen_3.0/20171207.001107~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f95ba50840e807f321cb66dd92e7b2761d3031b7;p=platform%2Fcore%2Fapi%2Fbluetooth.git gatt: Fix mismatching allocation and deallocation Mismatch in malloc and free or g_malloc and g_free Since allocation is happening from different pool, incorrect usage create issues Change-Id: I24c1ba8481fa6e016b029ed330ef3f03fd13e0a4 --- diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index 8c660f7..bd66b41 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -1957,9 +1957,7 @@ int bt_gatt_characteristic_create(const char *uuid, int permissions, if (value_length > 0) BT_CHECK_INPUT_PARAMETER(value); - chr = malloc(sizeof(*chr)); - if (chr == NULL) - return BT_ERROR_OUT_OF_MEMORY; + chr = g_malloc(sizeof(*chr)); memset(chr, 0x00, sizeof(*chr)); @@ -2224,10 +2222,7 @@ int bt_gatt_descriptor_create(const char *uuid, int permissions, if (value_length > 0) BT_CHECK_INPUT_PARAMETER(value); - desc = malloc(sizeof(*desc)); - if (desc == NULL) - return BT_ERROR_OUT_OF_MEMORY; - + desc = g_malloc(sizeof(*desc)); memset(desc, 0x00, sizeof(*desc)); desc->type = BT_GATT_TYPE_DESCRIPTOR; @@ -2774,7 +2769,7 @@ int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client) client_s->remote_address = g_strdup(remote_address); if (client_s->remote_address == NULL) { - free(client_s); + g_free(client_s); ret = BT_ERROR_OUT_OF_MEMORY; BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); return ret; diff --git a/src/bluetooth-proximity.c b/src/bluetooth-proximity.c index 7d45f1e..df1375b 100644 --- a/src/bluetooth-proximity.c +++ b/src/bluetooth-proximity.c @@ -236,7 +236,7 @@ int bt_proximity_monitor_create(const char *remote_address, bt_proximity_monitor monitor_s->remote_address = g_strdup(remote_address); if (monitor_s->remote_address == NULL) { - free(monitor_s); + g_free(monitor_s); error_code = BT_ERROR_OUT_OF_MEMORY; BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); return error_code;