diff --git a/src/advertising.c b/src/advertising.c
index a148625..59c8c3d 100644
--- a/src/advertising.c
+++ b/src/advertising.c
return NULL;
ad = new0(struct advertisement, 1);
- if (!ad)
- return NULL;
-
ad->client = g_dbus_client_new_full(conn, sender, path, path);
if (!ad->client)
goto fail;
struct btd_advertising *manager;
manager = new0(struct btd_advertising, 1);
- if (!manager)
- return NULL;
-
manager->adapter = adapter;
manager->mgmt = mgmt_new_default();
diff --git a/src/gatt-client.c b/src/gatt-client.c
index 4e52c5d..20a5ae6 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
return btd_error_in_progress(msg);
op = new0(struct async_dbus_op, 1);
- if (!op)
- return btd_error_failed(msg, "Failed to initialize request");
-
op->msg = dbus_message_ref(msg);
op->data = desc;
unsigned int id;
op = new0(struct async_dbus_op, 1);
- if (!op)
- return false;
-
op->msg = dbus_message_ref(msg);
op->data = data;
op->complete = complete;
unsigned int id;
op = new0(struct async_dbus_op, 1);
- if (!op)
- return false;
-
op->msg = dbus_message_ref(msg);
op->data = data;
op->complete = complete;
struct descriptor *desc;
desc = new0(struct descriptor, 1);
- if (!desc)
- return NULL;
-
desc->chrc = chrc;
desc->attr = attr;
desc->handle = gatt_db_attribute_get_handle(attr);
return btd_error_in_progress(msg);
op = new0(struct async_dbus_op, 1);
- if (!op)
- return btd_error_failed(msg, "Failed to initialize request");
-
op->msg = dbus_message_ref(msg);
op->data = chrc;
struct notify_client *client;
client = new0(struct notify_client, 1);
- if (!client)
- return NULL;
-
client->chrc = chrc;
client->owner = strdup(owner);
if (!client->owner) {
}
op = new0(struct async_dbus_op, 1);
- if (!op)
- goto fail;
-
op->data = client;
op->msg = dbus_message_ref(msg);
bt_uuid_t uuid;
chrc = new0(struct characteristic, 1);
- if (!chrc)
- return NULL;
-
chrc->descs = queue_new();
- if (!chrc->descs) {
- free(chrc);
- return NULL;
- }
-
chrc->notify_clients = queue_new();
- if (!chrc->notify_clients) {
- queue_destroy(chrc->descs, NULL);
- free(chrc);
- return NULL;
- }
-
chrc->service = service;
gatt_db_attribute_get_char_data(attr, &chrc->handle,
bt_uuid_t uuid;
service = new0(struct service, 1);
- if (!service)
- return NULL;
-
service->chrcs = queue_new();
- if (!service->chrcs) {
- free(service);
- return NULL;
- }
-
service->pending_ext_props = queue_new();
- if (!service->pending_ext_props) {
- queue_destroy(service->chrcs, NULL);
- free(service);
- return NULL;
- }
-
service->client = client;
gatt_db_attribute_get_service_data(attr, &service->start_handle,
return NULL;
client = new0(struct btd_gatt_client, 1);
- if (!client)
- return NULL;
-
client->services = queue_new();
- if (!client->services) {
- free(client);
- return NULL;
- }
-
client->all_notify_clients = queue_new();
- if (!client->all_notify_clients) {
- queue_destroy(client->services, NULL);
- free(client);
- return NULL;
- }
-
client->device = device;
ba2str(device_get_address(device), client->devaddr);
DBG("Re-register subscribed notification client");
op = new0(struct async_dbus_op, 1);
- if (!op)
- goto fail;
-
op->data = notify_client;
notify_client->notify_id = bt_gatt_client_register_notify(client->gatt,
async_dbus_op_free(op);
-fail:
DBG("Failed to re-register notification client");
queue_remove(notify_client->chrc->notify_clients, client);
diff --git a/src/gatt-database.c b/src/gatt-database.c
index 774b19e..e8ce7d5 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
struct device_state *dev_state;
dev_state = new0(struct device_state, 1);
- if (!dev_state)
- return NULL;
-
dev_state->ccc_states = queue_new();
- if (!dev_state->ccc_states) {
- free(dev_state);
- return NULL;
- }
-
bacpy(&dev_state->bdaddr, bdaddr);
dev_state->bdaddr_type = bdaddr_type;
return dev_state;
dev_state = device_state_create(bdaddr, bdaddr_type);
- if (!dev_state)
- return NULL;
queue_push_tail(database->device_states, dev_state);
struct ccc_state *ccc;
dev_state = get_device_state(database, bdaddr, bdaddr_type);
- if (!dev_state)
- return NULL;
ccc = find_ccc_state(dev_state, handle);
if (ccc)
return ccc;
ccc = new0(struct ccc_state, 1);
- if (!ccc)
- return NULL;
-
ccc->handle = handle;
queue_push_tail(dev_state->ccc_states, ccc);
}
ccc = get_ccc_state(database, &bdaddr, bdaddr_type, handle);
- if (!ccc) {
- ecode = BT_ATT_ERROR_UNLIKELY;
- goto done;
- }
len = 2 - offset;
value = len ? &ccc->value[offset] : NULL;
}
ccc = get_ccc_state(database, &bdaddr, bdaddr_type, handle);
- if (!ccc) {
- ecode = BT_ATT_ERROR_UNLIKELY;
- goto done;
- }
ccc_cb = queue_find(database->ccc_callbacks, ccc_cb_match_handle,
UINT_TO_PTR(gatt_db_attribute_get_handle(attrib)));
bt_uuid_t uuid;
ccc_cb = new0(struct ccc_cb_data, 1);
- if (!ccc_cb) {
- error("Could not allocate memory for callback data");
- return NULL;
- }
bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
ccc = gatt_db_service_add_descriptor(service, &uuid,
struct external_chrc *chrc;
chrc = new0(struct external_chrc, 1);
- if (!chrc)
- return NULL;
-
chrc->pending_reads = queue_new();
- if (!chrc->pending_reads) {
- free(chrc);
- return NULL;
- }
-
chrc->pending_writes = queue_new();
- if (!chrc->pending_writes) {
- queue_destroy(chrc->pending_reads, NULL);
- free(chrc);
- return NULL;
- }
chrc->path = g_strdup(path);
if (!chrc->path) {
struct external_desc *desc;
desc = new0(struct external_desc, 1);
- if (!desc)
- return NULL;
-
desc->pending_reads = queue_new();
- if (!desc->pending_reads) {
- free(desc);
- return NULL;
- }
-
desc->pending_writes = queue_new();
- if (!desc->pending_writes) {
- queue_destroy(desc->pending_reads, NULL);
- free(desc);
- return NULL;
- }
desc->chrc_path = g_strdup(chrc_path);
if (!desc->chrc_path) {
struct pending_op *op;
op = new0(struct pending_op, 1);
- if (!op)
- return NULL;
op->owner_queue = owner_queue;
op->attrib = attrib;
uint8_t ecode = BT_ATT_ERROR_UNLIKELY;
op = pending_read_new(owner_queue, attrib, id);
- if (!op) {
- error("Failed to allocate memory for pending read call");
- ecode = BT_ATT_ERROR_INSUFFICIENT_RESOURCES;
- goto error;
- }
if (g_dbus_proxy_method_call(proxy, "ReadValue", NULL, read_reply_cb,
op, pending_op_free) == TRUE)
pending_op_free(op);
-error:
gatt_db_attribute_read_result(attrib, id, ecode, NULL, 0);
}
struct pending_op *op;
op = new0(struct pending_op, 1);
- if (!op)
- return NULL;
op->data.iov_base = (uint8_t *) value;
op->data.iov_len = len;
uint8_t ecode = BT_ATT_ERROR_UNLIKELY;
op = pending_write_new(owner_queue, attrib, id, value, len);
- if (!op) {
- error("Failed to allocate memory for pending read call");
- ecode = BT_ATT_ERROR_INSUFFICIENT_RESOURCES;
- goto error;
- }
if (g_dbus_proxy_method_call(proxy, "WriteValue", write_setup_cb,
write_reply_cb, op,
pending_op_free(op);
-error:
gatt_db_attribute_write_result(attrib, id, ecode);
}
return NULL;
service = new0(struct external_service, 1);
- if (!service)
- return NULL;
service->client = g_dbus_client_new_full(conn, sender, path, path);
if (!service->client)
goto fail;
service->chrcs = queue_new();
- if (!service->chrcs)
- goto fail;
-
service->descs = queue_new();
- if (!service->descs)
- goto fail;
service->reg = dbus_message_ref(msg);
struct btd_profile *p;
p = new0(struct btd_profile, 1);
- if (!p)
- return -ENOMEM;
/* Assign directly to avoid having extra fields */
p->name = (const void *) g_strdup_printf("%s%s/%s", profile->owner,
return -EINVAL;
profile = new0(struct external_profile, 1);
- if (!profile)
- return -ENOMEM;
profile->owner = g_strdup(sender);
if (!profile->owner)
goto fail;
profile->profiles = queue_new();
- if (!profile->profiles)
- goto fail;
-
profile->database = database;
profile->id = g_dbus_add_disconnect_watch(conn, sender, profile_exited,
profile, NULL);
return NULL;
database = new0(struct btd_gatt_database, 1);
- if (!database)
- return NULL;
-
database->adapter = btd_adapter_ref(adapter);
database->db = gatt_db_new();
- if (!database->db)
- goto fail;
-
database->device_states = queue_new();
- if (!database->device_states)
- goto fail;
-
database->services = queue_new();
- if (!database->services)
- goto fail;
-
database->profiles = queue_new();
- if (!database->profiles)
- goto fail;
-
database->ccc_callbacks = queue_new();
- if (!database->ccc_callbacks)
- goto fail;
database->db_id = gatt_db_register(database->db, gatt_db_service_added,
gatt_db_service_removed,