Merge branch 'fix-some-variant-leaks' into 'main'

tests, GDesktopAppInfo: Fix various GVariant leaks

See merge request GNOME/glib!2874
This commit is contained in:
Marco Trevisan 2022-09-02 20:12:50 +00:00
commit 1d9a362bc7
4 changed files with 21 additions and 5 deletions

View File

@ -212,7 +212,7 @@ valgrind:
stage: analysis stage: analysis
needs: [] needs: []
variables: variables:
MESON_TEST_TIMEOUT_MULTIPLIER: 10 MESON_TEST_TIMEOUT_MULTIPLIER: 15
script: script:
- meson ${MESON_COMMON_OPTIONS} - meson ${MESON_COMMON_OPTIONS}
--werror --werror

View File

@ -3108,6 +3108,9 @@ launch_uris_with_dbus_signal_cb (GObject *object,
if (data->callback) if (data->callback)
data->callback (object, result, data->user_data); data->callback (object, result, data->user_data);
else if (!g_task_had_error (G_TASK (result)))
g_variant_unref (g_dbus_connection_call_finish (G_DBUS_CONNECTION (object),
result, NULL));
launch_uris_with_dbus_data_free (data); launch_uris_with_dbus_data_free (data);
} }
@ -3280,15 +3283,19 @@ launch_uris_with_dbus_cb (GObject *object,
{ {
GTask *task = G_TASK (user_data); GTask *task = G_TASK (user_data);
GError *local_error = NULL; GError *local_error = NULL;
GVariant *ret;
g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), result, &local_error); ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), result, &local_error);
if (local_error != NULL) if (local_error != NULL)
{ {
g_dbus_error_strip_remote_error (local_error); g_dbus_error_strip_remote_error (local_error);
g_task_return_error (task, g_steal_pointer (&local_error)); g_task_return_error (task, g_steal_pointer (&local_error));
} }
else else
g_task_return_boolean (task, TRUE); {
g_task_return_boolean (task, TRUE);
g_variant_unref (ret);
}
g_object_unref (task); g_object_unref (task);
} }

View File

@ -843,6 +843,7 @@ do_test_peer (void)
error = NULL; error = NULL;
value = g_dbus_proxy_get_cached_property (proxy, "PeerProperty"); value = g_dbus_proxy_get_cached_property (proxy, "PeerProperty");
g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "ThePropertyValue"); g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "ThePropertyValue");
g_clear_pointer (&value, g_variant_unref);
/* try invoking a method */ /* try invoking a method */
error = NULL; error = NULL;

View File

@ -119,13 +119,17 @@ request_name_cb (GObject *source,
GDBusConnection *connection = G_DBUS_CONNECTION (source); GDBusConnection *connection = G_DBUS_CONNECTION (source);
GError *error = NULL; GError *error = NULL;
GVariant *var; GVariant *var;
GVariant *child;
var = g_dbus_connection_call_finish (connection, res, &error); var = g_dbus_connection_call_finish (connection, res, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpuint (g_variant_get_uint32 (g_variant_get_child_value (var, 0)), child = g_variant_get_child_value (var, 0);
g_assert_cmpuint (g_variant_get_uint32 (child),
==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
release_name (connection, TRUE); release_name (connection, TRUE);
g_variant_unref (child);
g_variant_unref (var);
} }
static void static void
@ -154,11 +158,13 @@ release_name_cb (GObject *source,
GDBusConnection *connection = G_DBUS_CONNECTION (source); GDBusConnection *connection = G_DBUS_CONNECTION (source);
GError *error = NULL; GError *error = NULL;
GVariant *var; GVariant *var;
GVariant *child;
int i; int i;
var = g_dbus_connection_call_finish (connection, res, &error); var = g_dbus_connection_call_finish (connection, res, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpuint (g_variant_get_uint32 (g_variant_get_child_value (var, 0)), child = g_variant_get_child_value (var, 0);
g_assert_cmpuint (g_variant_get_uint32 (child),
==, DBUS_RELEASE_NAME_REPLY_RELEASED); ==, DBUS_RELEASE_NAME_REPLY_RELEASED);
/* generate some rapid NameOwnerChanged signals to try to trigger crashes */ /* generate some rapid NameOwnerChanged signals to try to trigger crashes */
@ -170,6 +176,8 @@ release_name_cb (GObject *source,
/* wait for dbus-daemon to catch up */ /* wait for dbus-daemon to catch up */
request_name (connection, TRUE); request_name (connection, TRUE);
g_variant_unref (child);
g_variant_unref (var);
} }
static void static void