gatt: proximity: Fix mismatching allocation and deallocation 71/134271/1
authorSyam Sidhardhan <s.syam@samsung.com>
Thu, 15 Jun 2017 14:27:19 +0000 (19:57 +0530)
committerSyam Sidhardhan <s.syam@samsung.com>
Thu, 15 Jun 2017 14:32:06 +0000 (20:02 +0530)
As per the glib documentation, the memory allocated using the glib
api's needs to be freed using corresponding glib free api's and not
libc api's, otherwise undefined behaviour can happen. This is because
the libc allocation and glib allocation uses different memory pools.
Similarly for libc api's.

Change-Id: I502ca5f143417c2ce4acf12e47b317d5339a48c1
Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
src/bluetooth-gatt.c
src/bluetooth-proximity.c

index 7d51c4bab98b21aeb78e3c5fce2593e4a1b743da..52f9632495a9660b9edcff5b9cf7fd2263b18a33 100644 (file)
@@ -1956,9 +1956,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));
 
@@ -2235,10 +2233,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;
@@ -2785,7 +2780,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;
index ae8f4f140a9adbfbb9c7c84f430e0fe306b90e9f..7070409845ad99ed8bf07d48c27089904435225b 100644 (file)
@@ -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;