summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/dbus-helper.c16
-rw-r--r--common/dbus.c58
-rw-r--r--hcid/dbus-adapter.c2
-rw-r--r--hcid/dbus-database.c12
-rw-r--r--hcid/dbus-hci.c26
-rw-r--r--hcid/dbus-manager.c2
-rw-r--r--hcid/dbus-security.c12
-rw-r--r--hcid/dbus-test.c4
8 files changed, 47 insertions, 85 deletions
diff --git a/common/dbus-helper.c b/common/dbus-helper.c
index 64b00cd8..7c14952b 100644
--- a/common/dbus-helper.c
+++ b/common/dbus-helper.c
@@ -90,7 +90,7 @@ static void generic_unregister(DBusConnection *connection, void *user_data)
if (data->unregister_function)
data->unregister_function(connection, data->user_data);
- free(data);
+ g_free(data);
}
static struct interface_data *find_interface(GSList *interfaces,
@@ -153,11 +153,7 @@ dbus_bool_t dbus_connection_create_object_path(DBusConnection *connection,
{
struct generic_data *data;
- data = malloc(sizeof(*data));
- if (!data)
- return FALSE;
-
- memset(data, 0, sizeof(*data));
+ data = g_new0(struct generic_data, 1);
data->user_data = user_data;
data->unregister_function = function;
@@ -167,7 +163,7 @@ dbus_bool_t dbus_connection_create_object_path(DBusConnection *connection,
if (dbus_connection_register_object_path(connection, path,
&generic_table, data) == FALSE) {
- free(data);
+ g_free(data);
return FALSE;
}
@@ -193,11 +189,7 @@ dbus_bool_t dbus_connection_register_interface(DBusConnection *connection,
(void *) &data) == FALSE)
return FALSE;
- iface = malloc(sizeof(*iface));
- if (!iface)
- return FALSE;
-
- memset(iface, 0, sizeof(*iface));
+ iface = g_new0(struct interface_data, 1);
iface->interface = interface;
iface->methods = methods;
diff --git a/common/dbus.c b/common/dbus.c
index bc1125fa..6cf4b192 100644
--- a/common/dbus.c
+++ b/common/dbus.c
@@ -110,14 +110,11 @@ static void name_data_free(struct name_data *data)
GSList *l;
for (l = data->callbacks; l != NULL; l = l->next)
- free(l->data);
+ g_free(l->data);
g_slist_free(data->callbacks);
-
- if (data->name)
- free(data->name);
-
- free(data);
+ g_free(data->name);
+ g_free(data);
}
static int name_data_add(const char *name, name_cb_t func, void *user_data)
@@ -126,9 +123,7 @@ static int name_data_add(const char *name, name_cb_t func, void *user_data)
struct name_data *data = NULL;
struct name_callback *cb = NULL;
- cb = malloc(sizeof(struct name_callback));
- if (!cb)
- goto failed;
+ cb = g_new(struct name_callback, 1);
cb->func = func;
cb->user_data = user_data;
@@ -139,30 +134,15 @@ static int name_data_add(const char *name, name_cb_t func, void *user_data)
goto done;
}
- data = malloc(sizeof(struct name_data));
- if (!data)
- goto failed;
-
- memset(data, 0, sizeof(struct name_data));
+ data = g_new0(struct name_data, 1);
- data->name = strdup(name);
- if (!data->name)
- goto failed;
+ data->name = g_strdup(name);
name_listeners = g_slist_append(name_listeners, data);
done:
data->callbacks = g_slist_append(data->callbacks, cb);
return first;
-
-failed:
- if (data)
- name_data_free(data);
-
- if (cb)
- free(cb);
-
- return 0;
}
static void name_data_remove(const char *name, name_cb_t func, void *user_data)
@@ -177,7 +157,7 @@ static void name_data_remove(const char *name, name_cb_t func, void *user_data)
cb = name_callback_find(data->callbacks, func, user_data);
if (cb) {
data->callbacks = g_slist_remove(data->callbacks, cb);
- free(cb);
+ g_free(cb);
}
if (!data->callbacks) {
@@ -291,7 +271,7 @@ int name_listener_remove(DBusConnection *connection, const char *name,
}
data->callbacks = g_slist_remove(data->callbacks, cb);
- free(cb);
+ g_free(cb);
/* Don't remove the filter if other callbacks exist */
if (data->callbacks)
@@ -434,9 +414,7 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data)
if (!dbus_watch_get_enabled(watch))
return TRUE;
- info = malloc(sizeof(struct watch_info));
- if (info == NULL)
- return FALSE;
+ info = g_new(struct watch_info, 1);
fd = dbus_watch_get_fd(watch);
info->io = g_io_channel_unix_new(fd);
@@ -464,7 +442,7 @@ static void remove_watch(DBusWatch *watch, void *data)
g_source_remove(info->watch_id);
g_io_channel_unref(info->io);
dbus_connection_unref(info->conn);
- free(info);
+ g_free(info);
}
}
@@ -498,7 +476,7 @@ static void timeout_handler_free(void *data)
return;
g_source_remove(handler->id);
- free(handler);
+ g_free(handler);
}
static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data)
@@ -508,8 +486,7 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data)
if (!dbus_timeout_get_enabled (timeout))
return TRUE;
- handler = malloc(sizeof(timeout_handler_t));
- memset(handler, 0, sizeof(timeout_handler_t));
+ handler = g_new0(timeout_handler_t, 1);
handler->timeout = timeout;
handler->id = g_timeout_add(dbus_timeout_get_interval(timeout),
@@ -595,12 +572,7 @@ DBusConnection *init_dbus(const char *name, void (*disconnect_cb)(void *), void
if (!disconnect_cb)
return conn;
- dc_data = malloc(sizeof(struct disconnect_data));
- if (!dc_data) {
- error("Allocating disconnect data failed");
- dbus_connection_unref(conn);
- return NULL;
- }
+ dc_data = g_new(struct disconnect_data, 1);
dc_data->disconnect_cb = disconnect_cb;
dc_data->user_data = user_data;
@@ -608,9 +580,9 @@ DBusConnection *init_dbus(const char *name, void (*disconnect_cb)(void *), void
dbus_connection_set_exit_on_disconnect(conn, FALSE);
if (!dbus_connection_add_filter(conn, disconnect_filter,
- dc_data, free)) {
+ dc_data, g_free)) {
error("Can't add D-Bus disconnect filter");
- free(dc_data);
+ g_free(dc_data);
dbus_connection_unref(conn);
return NULL;
}
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index 81f6bc35..d94c43b9 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -1716,7 +1716,7 @@ void dc_pending_timeout_cleanup(struct adapter *adapter)
{
dbus_connection_unref(adapter->pending_dc->conn);
dbus_message_unref(adapter->pending_dc->msg);
- free(adapter->pending_dc);
+ g_free(adapter->pending_dc);
adapter->pending_dc = NULL;
}
diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c
index ab3a6938..86053915 100644
--- a/hcid/dbus-database.c
+++ b/hcid/dbus-database.c
@@ -84,7 +84,7 @@ static void exit_callback(const char *name, void *user_data)
if (user_record->sender)
g_free(user_record->sender);
- free(user_record);
+ g_free(user_record);
}
static DBusHandlerResult add_service_record(DBusConnection *conn,
@@ -111,20 +111,20 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,
sdp_record = sdp_extract_pdu(record, &scanned);
if (!sdp_record) {
error("Parsing of service record failed");
- free(user_record);
+ g_free(user_record);
return error_failed(conn, msg, EIO);
}
if (scanned != len) {
error("Size mismatch of service record");
- free(user_record);
+ g_free(user_record);
sdp_record_free(sdp_record);
return error_failed(conn, msg, EIO);
}
if (add_record_to_server(sdp_record) < 0) {
error("Failed to register service record");
- free(user_record);
+ g_free(user_record);
sdp_record_free(sdp_record);
return error_failed(conn, msg, EIO);
}
@@ -136,7 +136,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,
if (register_sdp_binary((uint8_t *) record, size,
&user_record->handle) < 0) {
error("Failed to register service record");
- free(user_record);
+ g_free(user_record);
return error_failed(conn, msg, errno);
}
}
@@ -250,7 +250,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn,
if (user_record->sender)
g_free(user_record->sender);
- free(user_record);
+ g_free(user_record);
reply = dbus_message_new_method_return(msg);
if (!reply)
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index 5db47f4f..3d53b901 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -71,7 +71,7 @@ void bonding_request_free(struct bonding_request_info *bonding)
if (bonding->io)
g_io_channel_unref(bonding->io);
- free(bonding);
+ g_free(bonding);
}
int found_device_cmp(const struct remote_dev_info *d1,
@@ -159,7 +159,7 @@ static int found_device_remove(GSList **list, bdaddr_t *bdaddr)
dev = l->data;
*list = g_slist_remove(*list, dev);
- free(dev);
+ g_free(dev);
return 0;
}
@@ -421,7 +421,7 @@ int unregister_adapter_path(const char *path)
name_listener_remove(connection,
adapter->discov_requestor,
(name_cb_t) discover_devices_req_exit, adapter);
- free(adapter->discov_requestor);
+ g_free(adapter->discov_requestor);
adapter->discov_requestor = NULL;
}
@@ -430,7 +430,7 @@ int unregister_adapter_path(const char *path)
adapter->pdiscov_requestor,
(name_cb_t) periodic_discover_req_exit,
adapter);
- free(adapter->pdiscov_requestor);
+ g_free(adapter->pdiscov_requestor);
adapter->pdiscov_requestor = NULL;
}
@@ -510,7 +510,7 @@ int hcid_dbus_register_device(uint16_t id)
if (!dbus_connection_register_object_path(connection, path,
&adapter_vtable, adapter)) {
error("D-Bus failed to register %s object", path);
- free(adapter);
+ g_free(adapter);
return -1;
}
@@ -718,7 +718,7 @@ int hcid_dbus_stop_device(uint16_t id)
name_listener_remove(connection, adapter->discov_requestor,
(name_cb_t) discover_devices_req_exit,
adapter);
- free(adapter->discov_requestor);
+ g_free(adapter->discov_requestor);
adapter->discov_requestor = NULL;
}
@@ -726,7 +726,7 @@ int hcid_dbus_stop_device(uint16_t id)
name_listener_remove(connection, adapter->pdiscov_requestor,
(name_cb_t) periodic_discover_req_exit,
adapter);
- free(adapter->pdiscov_requestor);
+ g_free(adapter->pdiscov_requestor);
adapter->pdiscov_requestor = NULL;
}
@@ -1171,7 +1171,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
if (adapter->discov_requestor) {
name_listener_remove(connection, adapter->discov_requestor,
(name_cb_t) discover_devices_req_exit, adapter);
- free(adapter->discov_requestor);
+ g_free(adapter->discov_requestor);
adapter->discov_requestor = NULL;
/* If there is a pending reply for discovery cancel */
@@ -1281,7 +1281,7 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
name_listener_remove(connection, adapter->pdiscov_requestor,
(name_cb_t) periodic_discover_req_exit,
adapter);
- free(adapter->pdiscov_requestor);
+ g_free(adapter->pdiscov_requestor);
adapter->pdiscov_requestor = NULL;
}
@@ -1376,7 +1376,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
char *dev = l->data;
adapter->oor_devices = g_slist_remove(adapter->oor_devices,
dev);
- free(dev);
+ g_free(dev);
}
}
@@ -1414,7 +1414,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
name_status = NAME_NOT_REQUIRED;
if (name)
- free(name);
+ g_free(name);
name = tmp_name;
} else {
@@ -1432,7 +1432,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
DBUS_TYPE_INVALID);
send_message_and_unref(connection, signal_name);
- free(name);
+ g_free(name);
if (name_type != 0x08)
name_status = NAME_SENT;
@@ -1538,7 +1538,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
if (adapter->discov_requestor) {
name_listener_remove(connection, adapter->discov_requestor,
(name_cb_t) discover_devices_req_exit, adapter);
- free(adapter->discov_requestor);
+ g_free(adapter->discov_requestor);
adapter->discov_requestor = NULL;
/* If there is a pending reply for discovery cancel */
diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c
index d061e85a..a24db32f 100644
--- a/hcid/dbus-manager.c
+++ b/hcid/dbus-manager.c
@@ -151,7 +151,7 @@ static DBusHandlerResult list_adapters(DBusConnection *conn,
if (ioctl(sk, HCIGETDEVLIST, dl) < 0) {
int err = errno;
close(sk);
- free(dl);
+ g_free(dl);
return error_failed(conn, msg, err);
}
diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c
index 07a9490f..263517e1 100644
--- a/hcid/dbus-security.c
+++ b/hcid/dbus-security.c
@@ -119,18 +119,16 @@ static void passkey_agent_free(struct passkey_agent *agent)
if (!agent->exited)
release_agent(agent);
- if (agent->name)
- free(agent->name);
- if (agent->path)
- free(agent->path);
- if (agent->addr)
- free(agent->addr);
+ g_free(agent->name);
+ g_free(agent->path);
+ g_free(agent->addr);
+
if (agent->conn)
dbus_connection_unref(agent->conn);
g_slist_free(agent->pending_requests);
- free(agent);
+ g_free(agent);
}
static void agent_exited(const char *name, struct adapter *adapter)
diff --git a/hcid/dbus-test.c b/hcid/dbus-test.c
index 31b1392e..3d064c7f 100644
--- a/hcid/dbus-test.c
+++ b/hcid/dbus-test.c
@@ -107,9 +107,9 @@ static struct audit *audit_new(DBusConnection *conn, DBusMessage *msg,
static void audit_free(struct audit *audit)
{
- free(audit->requestor);
+ g_free(audit->requestor);
dbus_connection_unref(audit->conn);
- free(audit);
+ g_free(audit);
}
static void send_audit_status(struct audit *audit, const char *name)