From 7987325b2a1172a3dca2bfa055008a5eb183d7a8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 13:58:51 +0100 Subject: fd.o #27806: tp_account_set_enabled_async: don't second-guess the AccountManager We should still make the D-Bus call, even if the new value of Enabled matches the desired value: this could matter if two processes race with each other to set Enabled. As a side-effect, this fixes a reference leak of @result. --- telepathy-glib/account.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c index dd7945d2b..e474fc72e 100644 --- a/telepathy-glib/account.c +++ b/telepathy-glib/account.c @@ -1790,12 +1790,6 @@ tp_account_set_enabled_async (TpAccount *account, result = g_simple_async_result_new (G_OBJECT (account), callback, user_data, tp_account_set_enabled_finish); - if (priv->enabled == enabled) - { - g_simple_async_result_complete_in_idle (result); - return; - } - g_value_init (&value, G_TYPE_BOOLEAN); g_value_set_boolean (&value, enabled); -- cgit v1.2.3 From 42110a1be5f6b6eb126f56a46cf8dddeb57e159a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 14:24:18 +0100 Subject: TpDBusPropertiesMixin: gracefully deal with omitted getter/setter Strictly speaking this is a programming error, but this is consistent with how we deal with D-Bus methods. (TpTestsSimpleAccount doesn't have a setter yet, leading it to crash if a property is set.) --- telepathy-glib/dbus-properties-mixin.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/telepathy-glib/dbus-properties-mixin.c b/telepathy-glib/dbus-properties-mixin.c index 7a96f0c6e..1cfc17da5 100644 --- a/telepathy-glib/dbus-properties-mixin.c +++ b/telepathy-glib/dbus-properties-mixin.c @@ -763,6 +763,13 @@ tp_dbus_properties_mixin_get (GObject *self, return FALSE; } + if (iface_impl->getter == NULL) + { + g_set_error (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, + "Getting properties on %s is unimplemented", interface_name); + return FALSE; + } + g_value_init (value, prop_info->type); iface_impl->getter (self, iface_info->dbus_interface, prop_info->name, value, prop_impl->getter_data); @@ -938,7 +945,7 @@ _tp_dbus_properties_mixin_get_all (TpSvcDBusProperties *iface, iface_impl = _tp_dbus_properties_mixin_find_iface_impl (self, interface_name); - if (iface_impl == NULL) + if (iface_impl == NULL || iface_impl->getter == NULL) goto out; /* no properties, but we need to return that */ iface_info = iface_impl->mixin_priv; @@ -1016,6 +1023,15 @@ _tp_dbus_properties_mixin_set (TpSvcDBusProperties *iface, return; } + if (iface_impl->setter == NULL) + { + GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, + "Setting properties on this interface is unimplemented" }; + + dbus_g_method_return_error (context, &e); + return; + } + if (G_VALUE_TYPE (value) != prop_info->type) { g_value_init (©, prop_info->type); -- cgit v1.2.3 From a54835b7454dbc99014349bebaf32bf52410664c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 14:24:53 +0100 Subject: tests: add tp_tests_run_until_result, tp_tests_result_ready_cb --- tests/lib/util.c | 25 ++++++++++++++++++------- tests/lib/util.h | 4 ++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/lib/util.c b/tests/lib/util.c index 4b3fd4fd2..6b6d5d0bc 100644 --- a/tests/lib/util.c +++ b/tests/lib/util.c @@ -20,8 +20,10 @@ tp_tests_proxy_run_until_prepared (gpointer proxy, g_assert_no_error (error); } -static void -prepared_cb (GObject *object, +/* A GAsyncReadyCallback whose user_data is a GAsyncResult **. It writes a + * reference to the result into that pointer. */ +void +tp_tests_result_ready_cb (GObject *object, GAsyncResult *res, gpointer user_data) { @@ -30,6 +32,18 @@ prepared_cb (GObject *object, *result = g_object_ref (res); } +/* Run until *result contains a result. Intended to be used with a pending + * async call that uses tp_tests_result_ready_cb. */ +void +tp_tests_run_until_result (GAsyncResult **result) +{ + /* not synchronous */ + g_assert (*result == NULL); + + while (*result == NULL) + g_main_context_iteration (NULL, TRUE); +} + gboolean tp_tests_proxy_run_until_prepared_or_failed (gpointer proxy, const GQuark *features, @@ -38,12 +52,9 @@ tp_tests_proxy_run_until_prepared_or_failed (gpointer proxy, GAsyncResult *result = NULL; gboolean r; - tp_proxy_prepare_async (proxy, features, prepared_cb, &result); - /* not synchronous */ - g_assert (result == NULL); + tp_proxy_prepare_async (proxy, features, tp_tests_result_ready_cb, &result); - while (result == NULL) - g_main_context_iteration (NULL, TRUE); + tp_tests_run_until_result (&result); r = tp_proxy_prepare_finish (proxy, result, error); g_object_unref (result); diff --git a/tests/lib/util.h b/tests/lib/util.h index d3433ccf9..bc150d6af 100644 --- a/tests/lib/util.h +++ b/tests/lib/util.h @@ -48,4 +48,8 @@ void tp_tests_create_and_connect_conn (GType conn_type, gpointer tp_tests_object_new_static_class (GType type, ...) G_GNUC_NULL_TERMINATED; +void tp_tests_run_until_result (GAsyncResult **result); +void tp_tests_result_ready_cb (GObject *object, + GAsyncResult *res, gpointer user_data); + #endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */ -- cgit v1.2.3 From 666b8012ea593db2c7ce060040a0d91c9b6db784 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 14:25:16 +0100 Subject: tests/dbus/account.c: add a very noddy test for tp_account_set_enabled_async --- tests/dbus/account.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/dbus/account.c b/tests/dbus/account.c index 2c011d4f9..a6e95e2ed 100644 --- a/tests/dbus/account.c +++ b/tests/dbus/account.c @@ -85,6 +85,7 @@ typedef struct { gulong notify_id; /* g_strdup (property name) => GUINT_TO_POINTER (counter) */ GHashTable *times_notified; + GAsyncResult *result; GError *error /* initialized where needed */; TpTestsSimpleAccount *account_service /* initialized in prepare_service */; @@ -189,6 +190,9 @@ teardown (Test *test, test->dbus = NULL; g_main_loop_unref (test->mainloop); test->mainloop = NULL; + + g_clear_error (&test->error); + tp_clear_object (&test->result); } static void @@ -230,6 +234,23 @@ test_new (Test *test, g_assert (test->account != NULL); } +static void +test_setters (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + test->account = tp_account_new (test->dbus, + "/org/freedesktop/Telepathy/Account/what/ev/er", NULL); + g_assert (test->account != NULL); + + tp_account_set_enabled_async (test->account, TRUE, tp_tests_result_ready_cb, + &test->result); + tp_tests_run_until_result (&test->result); + tp_account_set_enabled_finish (test->account, test->result, &test->error); + g_assert_error (test->error, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED); + g_clear_error (&test->error); + tp_clear_object (&test->result); +} + static void account_prepare_cb (GObject *source, GAsyncResult *result, @@ -530,6 +551,9 @@ main (int argc, g_test_add ("/account/new", Test, NULL, setup, test_new, teardown); + g_test_add ("/account/setters", Test, NULL, setup_service, test_setters, + teardown_service); + g_test_add ("/account/prepare/success", Test, NULL, setup_service, test_prepare_success, teardown_service); -- cgit v1.2.3 From 7b697ae80c2ec1a9b15cb7fca7f8983bd9f0d7a1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 16:03:21 +0100 Subject: _tp_cm_param_spec_check_all_allowed: don't leak temporary hash table --- telepathy-glib/base-protocol.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/telepathy-glib/base-protocol.c b/telepathy-glib/base-protocol.c index 9a5867040..5b982a562 100644 --- a/telepathy-glib/base-protocol.c +++ b/telepathy-glib/base-protocol.c @@ -850,6 +850,7 @@ _tp_cm_param_spec_check_all_allowed (const TpCMParamSpec *parameters, { GHashTable *tmp = g_hash_table_new (g_str_hash, g_str_equal); const TpCMParamSpec *iter; + gboolean ret = TRUE; tp_g_hash_table_update (tmp, asv, NULL, NULL); @@ -879,10 +880,12 @@ _tp_cm_param_spec_check_all_allowed (const TpCMParamSpec *parameters, g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, "%s", error_txt); g_free (error_txt); - return FALSE; + ret = FALSE; } - return TRUE; + g_hash_table_unref (tmp); + + return ret; } static GValue * -- cgit v1.2.3 From 60de68b64ad7870590ef9c3565f80165e2be90c8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 16:03:32 +0100 Subject: tp_protocol_finalize: don't leak icon name --- telepathy-glib/protocol.c | 1 + 1 file changed, 1 insertion(+) diff --git a/telepathy-glib/protocol.c b/telepathy-glib/protocol.c index 239eeba59..e55538906 100644 --- a/telepathy-glib/protocol.c +++ b/telepathy-glib/protocol.c @@ -360,6 +360,7 @@ tp_protocol_finalize (GObject *object) _tp_connection_manager_protocol_free_contents (&self->priv->protocol_struct); g_free (self->priv->vcard_field); g_free (self->priv->english_name); + g_free (self->priv->icon_name); if (self->priv->protocol_properties != NULL) g_hash_table_unref (self->priv->protocol_properties); -- cgit v1.2.3 From 184da485a8b37efdb2531621b57a8bd1da806ec4 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 16:03:49 +0100 Subject: tests/dbus/channel-introspect: don't leak result object --- tests/dbus/channel-introspect.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/dbus/channel-introspect.c b/tests/dbus/channel-introspect.c index 0bbb19fef..25e5aa771 100644 --- a/tests/dbus/channel-introspect.c +++ b/tests/dbus/channel-introspect.c @@ -757,6 +757,7 @@ main (int argc, MYASSERT (!tp_proxy_prepare_finish (chan, prepare_result, &error), ""); g_assert_error (error, invalidated->domain, invalidated->code); g_assert_cmpstr (error->message, ==, invalidated->message); + tp_clear_object (&prepare_result); g_clear_error (&error); g_clear_error (&invalidated); -- cgit v1.2.3 From ff498d4ebcc9554ad8a5e1412b0ae13c63558849 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 16:04:01 +0100 Subject: test_tp_contact_feature: don't leak enum class --- tests/enums.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/enums.c b/tests/enums.c index 1b2f2c78c..d43a0e57d 100644 --- a/tests/enums.c +++ b/tests/enums.c @@ -28,6 +28,8 @@ test_tp_contact_feature (void) g_assert (G_IS_ENUM_CLASS (klass)); g_assert_cmpint (klass->n_values, ==, NUM_TP_CONTACT_FEATURES); + + g_type_class_unref (klass); } -- cgit v1.2.3 From 4d5e110c58c9c722443a16bb286678199668452b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 10 Sep 2010 16:04:17 +0100 Subject: telepathy-glib.supp: ignore g_get_home_dir's one-per-process leak --- tools/telepathy-glib.supp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/telepathy-glib.supp b/tools/telepathy-glib.supp index b3bc3f4a6..28bd5a06a 100644 --- a/tools/telepathy-glib.supp +++ b/tools/telepathy-glib.supp @@ -103,6 +103,13 @@ fun:g_get_charset } +{ + one g_get_home_dir per process + Memcheck:Leak + ... + fun:g_get_home_dir +} + { GQuarks can't be freed Memcheck:Leak -- cgit v1.2.3