From 37ba9e25fb8ed1327a305617040f993ad453b6a9 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 21 Jan 2014 14:46:47 +0200 Subject: [PATCH] core: Don't use GLib allocators for bt_uuid2string and bt_name2string --- src/adapter.c | 10 +++++----- src/device.c | 20 ++++++++++---------- src/eir.c | 18 +++++++++++++++--- src/profile.c | 22 +++++++++++----------- src/uuid-helper.c | 11 +++++------ 5 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index b8e790e09..570a5bff5 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2099,7 +2099,7 @@ static gboolean property_get_uuids(const GDBusPropertyTable *property, dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &uuid); - g_free(uuid); + free(uuid); } dbus_message_iter_close_container(iter, &entry); @@ -3283,7 +3283,7 @@ static gboolean record_has_uuid(const sdp_record_t *rec, ret = strcasecmp(uuid, profile_uuid); - g_free(uuid); + free(uuid); if (ret == 0) return TRUE; @@ -3424,8 +3424,8 @@ static void convert_sdp_entry(char *key, char *value, void *user_data) failed: sdp_record_free(rec); - g_free(prim_uuid); - g_free(att_uuid); + free(prim_uuid); + free(att_uuid); } static void convert_primaries_entry(char *key, char *value, void *user_data) @@ -3506,7 +3506,7 @@ static void convert_primaries_entry(char *key, char *value, void *user_data) end: g_free(data); - g_free(prim_uuid); + free(prim_uuid); g_key_file_free(key_file); } diff --git a/src/device.c b/src/device.c index aa15e0aaf..b069a1a70 100644 --- a/src/device.c +++ b/src/device.c @@ -1389,7 +1389,7 @@ static DBusMessage *connect_profile(DBusConnection *conn, DBusMessage *msg, uuid = bt_name2string(pattern); reply = connect_profiles(dev, msg, uuid); - g_free(uuid); + free(uuid); return reply; } @@ -1430,7 +1430,7 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg, return btd_error_invalid_args(msg); service = find_connectable_service(dev, uuid); - g_free(uuid); + free(uuid); if (!service) return btd_error_invalid_args(msg); @@ -2130,7 +2130,7 @@ static void load_att_info(struct btd_device *device, const char *local, service_uuid = bt_uuid2string(&uuid); memcpy(prim->uuid, service_uuid, MAX_LEN_UUID_STR); - g_free(service_uuid); + free(service_uuid); g_free(str); device->primaries = g_slist_append(device->primaries, prim); @@ -2138,7 +2138,7 @@ static void load_att_info(struct btd_device *device, const char *local, g_strfreev(groups); g_key_file_free(key_file); - g_free(prim_uuid); + free(prim_uuid); } static struct btd_device *device_new(struct btd_adapter *adapter, @@ -2474,7 +2474,7 @@ static gboolean record_has_uuid(const sdp_record_t *rec, ret = strcasecmp(uuid, profile_uuid); - g_free(uuid); + free(uuid); if (ret == 0) return TRUE; @@ -2676,8 +2676,8 @@ static void store_primaries_from_sdp_record(GKeyFile *key_file, g_key_file_set_integer(key_file, handle, "EndGroupHandle", end); done: - g_free(prim_uuid); - g_free(att_uuid); + free(prim_uuid); + free(att_uuid); } static int rec_cmp(const void *a, const void *b) @@ -2800,7 +2800,7 @@ static void update_bredr_services(struct browse_req *req, sdp_list_t *recs) store_primaries_from_sdp_record(att_key_file, rec); next: - g_free(profile_uuid); + free(profile_uuid); sdp_list_free(svcclass, free); } @@ -2889,7 +2889,7 @@ static GSList *device_services_from_record(struct btd_device *device, prim_list = g_slist_append(prim_list, prim); } - g_free(att_uuid); + free(att_uuid); return prim_list; } @@ -3051,7 +3051,7 @@ static void store_services(struct btd_device *device) g_file_set_contents(filename, data, length, NULL); } - g_free(prim_uuid); + free(prim_uuid); g_free(data); g_key_file_free(key_file); } diff --git a/src/eir.c b/src/eir.c index f18a9189e..ebc79b549 100644 --- a/src/eir.c +++ b/src/eir.c @@ -67,7 +67,11 @@ static void eir_parse_uuid16(struct eir_data *eir, const void *data, service.value.uuid16 = bt_get_le16(uuid16); uuid_str = bt_uuid2string(&service); - eir->services = g_slist_append(eir->services, uuid_str); + if (!uuid_str) + continue; + eir->services = g_slist_append(eir->services, + g_strdup(uuid_str)); + free(uuid_str); } } @@ -84,7 +88,11 @@ static void eir_parse_uuid32(struct eir_data *eir, const void *data, service.value.uuid32 = bt_get_le32(uuid32); uuid_str = bt_uuid2string(&service); - eir->services = g_slist_append(eir->services, uuid_str); + if (!uuid_str) + continue; + eir->services = g_slist_append(eir->services, + g_strdup(uuid_str)); + free(uuid_str); } } @@ -102,7 +110,11 @@ static void eir_parse_uuid128(struct eir_data *eir, const uint8_t *data, for (k = 0; k < 16; k++) service.value.uuid128.data[k] = uuid_ptr[16 - k - 1]; uuid_str = bt_uuid2string(&service); - eir->services = g_slist_append(eir->services, uuid_str); + if (!uuid_str) + continue; + eir->services = g_slist_append(eir->services, + g_strdup(uuid_str)); + free(uuid_str); uuid_ptr += 16; } } diff --git a/src/profile.c b/src/profile.c index 0862a3668..ecbb1c5d5 100644 --- a/src/profile.c +++ b/src/profile.c @@ -2146,7 +2146,7 @@ static int parse_ext_opt(struct ext_profile *ext, const char *key, if (type != DBUS_TYPE_STRING) return -EINVAL; dbus_message_iter_get_basic(value, &str); - g_free(ext->service); + free(ext->service); ext->service = bt_name2string(str); } @@ -2156,27 +2156,27 @@ static int parse_ext_opt(struct ext_profile *ext, const char *key, static void set_service(struct ext_profile *ext) { if (strcasecmp(ext->uuid, HSP_HS_UUID) == 0) { - ext->service = g_strdup(ext->uuid); + ext->service = strdup(ext->uuid); } else if (strcasecmp(ext->uuid, HSP_AG_UUID) == 0) { ext->service = ext->uuid; - ext->uuid = g_strdup(HSP_HS_UUID); + ext->uuid = strdup(HSP_HS_UUID); } else if (strcasecmp(ext->uuid, HFP_HS_UUID) == 0) { - ext->service = g_strdup(ext->uuid); + ext->service = strdup(ext->uuid); } else if (strcasecmp(ext->uuid, HFP_AG_UUID) == 0) { ext->service = ext->uuid; - ext->uuid = g_strdup(HFP_HS_UUID); + ext->uuid = strdup(HFP_HS_UUID); } else if (strcasecmp(ext->uuid, OBEX_SYNC_UUID) == 0 || strcasecmp(ext->uuid, OBEX_OPP_UUID) == 0 || strcasecmp(ext->uuid, OBEX_FTP_UUID) == 0) { - ext->service = g_strdup(ext->uuid); + ext->service = strdup(ext->uuid); } else if (strcasecmp(ext->uuid, OBEX_PSE_UUID) == 0 || strcasecmp(ext->uuid, OBEX_PCE_UUID) == 0) { ext->service = ext->uuid; - ext->uuid = g_strdup(OBEX_PBAP_UUID); + ext->uuid = strdup(OBEX_PBAP_UUID); } else if (strcasecmp(ext->uuid, OBEX_MAS_UUID) == 0 || strcasecmp(ext->uuid, OBEX_MNS_UUID) == 0) { ext->service = ext->uuid; - ext->uuid = g_strdup(OBEX_MAP_UUID); + ext->uuid = strdup(OBEX_MAP_UUID); } } @@ -2275,8 +2275,8 @@ static void remove_ext(struct ext_profile *ext) g_free(ext->remote_uuid); g_free(ext->name); g_free(ext->owner); - g_free(ext->uuid); - g_free(ext->service); + free(ext->uuid); + free(ext->service); g_free(ext->role); g_free(ext->path); g_free(ext->record); @@ -2397,7 +2397,7 @@ bool btd_profile_add_custom_prop(const char *uuid, const char *type, prop = g_new0(struct btd_profile_custom_property, 1); - prop->uuid = g_strdup(uuid); + prop->uuid = strdup(uuid); prop->type = g_strdup(type); prop->name = g_strdup(name); prop->exists = exists; diff --git a/src/uuid-helper.c b/src/uuid-helper.c index 1995ea1a6..3cca02446 100644 --- a/src/uuid-helper.c +++ b/src/uuid-helper.c @@ -72,6 +72,7 @@ char *bt_uuid2string(uuid_t *uuid) unsigned short data3; unsigned int data4; unsigned short data5; + int err; if (!uuid) return NULL; @@ -98,14 +99,12 @@ char *bt_uuid2string(uuid_t *uuid) memcpy(&data4, &uuid128.value.uuid128.data[10], 4); memcpy(&data5, &uuid128.value.uuid128.data[14], 2); - str = g_try_malloc0(MAX_LEN_UUID_STR); - if (!str) - return NULL; - - sprintf(str, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", + err = asprintf(&str, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", g_ntohl(data0), g_ntohs(data1), g_ntohs(data2), g_ntohs(data3), g_ntohl(data4), g_ntohs(data5)); + if (err < 0) + return NULL; return str; } @@ -187,7 +186,7 @@ char *bt_name2string(const char *pattern) /* UUID 128 string format */ if (is_uuid128(pattern)) - return g_strdup(pattern); + return strdup(pattern); /* Friendly service name format */ uuid16 = name2class(pattern); -- 2.47.3