[gnome-bluetooth/wip/hadess/cleanups: 10/24] lib: Use g_autoptr to free GError
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/wip/hadess/cleanups: 10/24] lib: Use g_autoptr to free GError
- Date: Wed, 17 Feb 2021 11:02:23 +0000 (UTC)
commit 859a7d02282b956b9b6eaab715af3a4182d3eb94
Author: Bastien Nocera <hadess hadess net>
Date: Wed Feb 10 16:33:51 2021 +0100
lib: Use g_autoptr to free GError
lib/bluetooth-agent.c | 16 +++++-----------
lib/bluetooth-client.c | 6 ++----
2 files changed, 7 insertions(+), 15 deletions(-)
---
diff --git a/lib/bluetooth-agent.c b/lib/bluetooth-agent.c
index 0fce134b..54f2726a 100644
--- a/lib/bluetooth-agent.c
+++ b/lib/bluetooth-agent.c
@@ -283,7 +283,7 @@ static gboolean bluetooth_agent_cancel(BluetoothAgent *agent,
static void
register_agent (BluetoothAgentPrivate *priv)
{
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean ret;
ret = agent_manager1_call_register_agent_sync (priv->agent_manager,
@@ -292,17 +292,14 @@ register_agent (BluetoothAgentPrivate *priv)
NULL, &error);
if (ret == FALSE) {
g_printerr ("Agent registration failed: %s\n", error->message);
- g_error_free (error);
return;
}
ret = agent_manager1_call_request_default_agent_sync (priv->agent_manager,
priv->path,
NULL, &error);
- if (ret == FALSE) {
+ if (ret == FALSE)
g_printerr ("Agent registration as default failed: %s\n", error->message);
- g_error_free (error);
- }
}
static void
@@ -453,7 +450,7 @@ handle_method_call (GDBusConnection *connection,
BluetoothAgentPrivate *priv = BLUETOOTH_AGENT_GET_PRIVATE(agent);
if (g_str_equal (sender, priv->busname) == FALSE) {
- GError *error = NULL;
+ GError *error;
error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT,
"Permission Denied");
g_dbus_method_invocation_take_error(invocation, error);
@@ -517,7 +514,7 @@ static const GDBusInterfaceVTable interface_vtable =
gboolean bluetooth_agent_register(BluetoothAgent *agent)
{
BluetoothAgentPrivate *priv;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
g_return_val_if_fail (BLUETOOTH_IS_AGENT (agent), FALSE);
@@ -532,8 +529,6 @@ gboolean bluetooth_agent_register(BluetoothAgent *agent)
&error);
if (priv->reg_id == 0) {
g_warning ("Failed to register object: %s", error->message);
- g_error_free (error);
- error = NULL;
return FALSE;
}
@@ -563,7 +558,7 @@ error_matches_remote_error (GError *error,
gboolean bluetooth_agent_unregister(BluetoothAgent *agent)
{
BluetoothAgentPrivate *priv;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
g_return_val_if_fail (BLUETOOTH_IS_AGENT (agent), FALSE);
@@ -582,7 +577,6 @@ gboolean bluetooth_agent_unregister(BluetoothAgent *agent)
error->message,
g_quark_to_string (error->domain));
}
- g_error_free(error);
}
g_object_unref(priv->agent_manager);
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index d537cd70..6376bf3d 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -1425,7 +1425,6 @@ bluetooth_client_setup_device (BluetoothClient *client,
g_autoptr(GDBusProxy) device = NULL;
GtkTreeIter iter, adapter_iter;
gboolean paired;
- GError *err = NULL;
g_return_if_fail (BLUETOOTH_IS_CLIENT (client));
@@ -1453,6 +1452,7 @@ bluetooth_client_setup_device (BluetoothClient *client,
if (paired != FALSE &&
gtk_tree_model_iter_parent (GTK_TREE_MODEL(priv->store), &adapter_iter, &iter)) {
GDBusProxy *adapter;
+ g_autoptr(GError) err = NULL;
gtk_tree_model_get (GTK_TREE_MODEL(priv->store), &adapter_iter,
BLUETOOTH_COLUMN_PROXY, &adapter,
@@ -1460,10 +1460,8 @@ bluetooth_client_setup_device (BluetoothClient *client,
adapter1_call_remove_device_sync (ADAPTER1 (adapter),
path,
NULL, &err);
- if (err != NULL) {
+ if (err != NULL)
g_warning ("Failed to remove device: %s", err->message);
- g_error_free (err);
- }
g_object_unref (adapter);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]