[gnome-bluetooth/wip/hadess/fix-set-trusted: 2/3] client: Clarify return value's ownership
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/wip/hadess/fix-set-trusted: 2/3] client: Clarify return value's ownership
- Date: Fri, 22 Mar 2019 15:27:36 +0000 (UTC)
commit 43d2e46986f9b9032cdb4f2aa5217fb06d731243
Author: Bastien Nocera <hadess hadess net>
Date: Fri Mar 22 16:10:58 2019 +0100
client: Clarify return value's ownership
bluetooth_client_setup_device_finish() stole the device path from the
result object but didn't mention it. Clarify the ownership of the "path"
return value, and make sure that it's only set on success.
lib/bluetooth-client.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index e7aa850e..10adf4d9 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -1373,16 +1373,27 @@ bluetooth_client_setup_device_finish (BluetoothClient *client,
GError **error)
{
GSimpleAsyncResult *simple;
+ char *object_path;
+ gboolean ret;
+
+ g_return_val_if_fail (path != NULL, FALSE);
+ *path = NULL;
simple = (GSimpleAsyncResult *) res;
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == bluetooth_client_setup_device);
- if (path != NULL)
- *path = g_object_get_data (G_OBJECT (res), "device-object-path");
+ ret = g_simple_async_result_get_op_res_gboolean (simple);
+ object_path = g_strdup (g_object_get_data (G_OBJECT (res), "device-object-path"));
+ g_debug ("bluetooth_client_setup_device_finish() %s (path: %s)",
+ ret ? "success" : "failure", object_path);
- if (g_simple_async_result_get_op_res_gboolean (simple))
+ if (ret) {
+ *path = object_path;
return TRUE;
+ }
+
+ g_free (object_path);
g_simple_async_result_propagate_error (simple, error);
return FALSE;
}
@@ -1409,7 +1420,8 @@ bluetooth_client_setup_device (BluetoothClient *client,
user_data,
bluetooth_client_setup_device);
g_simple_async_result_set_check_cancellable (simple, cancellable);
- g_object_set_data (G_OBJECT (simple), "device-object-path", g_strdup (path));
+ g_object_set_data_full (G_OBJECT (simple), "device-object-path",
+ g_strdup (path), (GDestroyNotify) g_free);
if (get_iter_from_path (priv->store, &iter, path) == FALSE) {
g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]