Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GVariant, GError and g_autoptr cleanups #1439

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ handle_set_selection (XdpDbusClipboard *object,
Call *call = call_from_invocation (invocation);
Session *session;
GVariantBuilder options_builder;
GVariant *options;
g_autoptr(GVariant) options = NULL;
g_autoptr(GError) error = NULL;

session = acquire_session_from_call (arg_session_handle, call);
Expand Down Expand Up @@ -156,7 +156,7 @@ handle_set_selection (XdpDbusClipboard *object,
g_dbus_method_invocation_return_gerror (invocation, error);
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
options = g_variant_builder_end (&options_builder);
options = g_variant_ref_sink (g_variant_builder_end (&options_builder));

xdp_dbus_impl_clipboard_call_set_selection (
impl, arg_session_handle, options, NULL, NULL, NULL);
Expand Down
13 changes: 8 additions & 5 deletions src/dynamic-launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ set_launcher_data_for_token (const char *token,
{
g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&transient_permissions_lock);
guint timeout_id;
GVariant *launcher_data_wrapped;
g_autoptr(GVariant) launcher_data_wrapped = NULL;

if (!transient_permissions)
{
Expand All @@ -464,11 +464,12 @@ set_launcher_data_for_token (const char *token,
*/
timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 300, install_token_timeout,
g_strdup (token), g_free);
launcher_data_wrapped = g_variant_new ("(vu)", launcher_data, timeout_id);
launcher_data_wrapped =
g_variant_ref_sink (g_variant_new ("(vu)", launcher_data, timeout_id));

g_hash_table_insert (transient_permissions,
g_strdup (token),
g_variant_ref_sink (launcher_data_wrapped));
g_steal_pointer (&launcher_data_wrapped));
}

static void
Expand All @@ -477,7 +478,6 @@ prepare_install_done (GObject *source,
gpointer data)
{
g_autoptr(Request) request = data;
GVariant *launcher_data;
guint response = 2;
g_autoptr(GVariant) results = NULL;
g_autoptr(GError) error = NULL;
Expand Down Expand Up @@ -524,6 +524,8 @@ prepare_install_done (GObject *source,
}
else
{
GVariant *launcher_data;

/* Save the token in memory and return it to the caller */
launcher_data = g_variant_new ("(svss)", chosen_name, chosen_icon, icon_format, icon_size);
set_launcher_data_for_token (token, launcher_data);
Expand Down Expand Up @@ -686,7 +688,6 @@ handle_request_install_token (XdpDbusDynamicLauncher *object,
Call *call = call_from_invocation (invocation);
const char *app_id = xdp_app_info_get_id (call->app_info);
g_autoptr(GError) error = NULL;
GVariant *launcher_data;
g_autofree char *token = NULL;
g_autofree char *icon_format = NULL;
g_autofree char *icon_size = NULL;
Expand Down Expand Up @@ -716,6 +717,8 @@ handle_request_install_token (XdpDbusDynamicLauncher *object,

if (response == 0)
{
GVariant *launcher_data;

/* Do some validation on the icon before saving it */
if (!validate_serialized_icon (arg_icon_v, &icon_format, &icon_size))
{
Expand Down
8 changes: 4 additions & 4 deletions src/global-shortcuts.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ handle_create_session (XdpDbusGlobalShortcuts *object,
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

options = g_variant_builder_end (&options_builder);
options = g_variant_ref_sink (g_variant_builder_end (&options_builder));
impl_request =
xdp_dbus_impl_request_proxy_new_sync (g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)),
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
Expand Down Expand Up @@ -390,7 +390,7 @@ handle_bind_shortcuts (XdpDbusGlobalShortcuts *object,
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

options = g_variant_builder_end (&options_builder);
options = g_variant_ref_sink (g_variant_builder_end (&options_builder));

g_variant_builder_init (&shortcuts_builder, G_VARIANT_TYPE_ARRAY);
if (!xdp_verify_shortcuts (arg_shortcuts, &shortcuts_builder,
Expand All @@ -400,7 +400,7 @@ handle_bind_shortcuts (XdpDbusGlobalShortcuts *object,
g_dbus_method_invocation_return_gerror (invocation, error);
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
shortcuts = g_variant_builder_end (&shortcuts_builder);
shortcuts = g_variant_ref_sink (g_variant_builder_end (&shortcuts_builder));

session = acquire_session (arg_session_handle, request);
if (!session)
Expand Down Expand Up @@ -517,7 +517,7 @@ handle_list_shortcuts (XdpDbusGlobalShortcuts *object,
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

options = g_variant_builder_end (&options_builder);
options = g_variant_ref_sink (g_variant_builder_end (&options_builder));

session = acquire_session (arg_session_handle, request);
if (!session)
Expand Down
23 changes: 12 additions & 11 deletions src/input-capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ handle_create_session (XdpDbusInputCapture *object,
g_autoptr(XdpDbusImplRequest) impl_request = NULL;
g_autoptr(GError) error = NULL;
GVariantBuilder options_builder;
GVariant *options;
g_autoptr(GVariant) options = NULL;
Session *session;

REQUEST_AUTOLOCK (request);
Expand Down Expand Up @@ -269,7 +269,7 @@ handle_create_session (XdpDbusInputCapture *object,
g_dbus_method_invocation_return_gerror (invocation, error);
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
options = g_variant_builder_end (&options_builder);
options = g_variant_ref_sink (g_variant_builder_end (&options_builder));

g_object_set_qdata_full (G_OBJECT (request),
quark_request_session,
Expand Down Expand Up @@ -325,12 +325,12 @@ get_zones_done (GObject *source_object,

if (request->exported)
{
if (response != 0)
if (!results)
{
GVariantBuilder results_builder;

g_variant_builder_init (&results_builder, G_VARIANT_TYPE_VARDICT);
results = g_variant_builder_end (&results_builder);
results = g_variant_ref_sink (g_variant_builder_end (&results_builder));
}

xdp_dbus_request_emit_response (XDP_DBUS_REQUEST (request), response, results);
Expand All @@ -357,7 +357,7 @@ handle_get_zones (XdpDbusInputCapture *object,
InputCaptureSession *input_capture_session;
g_autoptr(GError) error = NULL;
GVariantBuilder options_builder;
GVariant *options;
g_autoptr(GVariant) options = NULL;
Session *session;

REQUEST_AUTOLOCK (request);
Expand Down Expand Up @@ -425,7 +425,7 @@ handle_get_zones (XdpDbusInputCapture *object,
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

options = g_variant_builder_end (&options_builder);
options = g_variant_ref_sink (g_variant_builder_end (&options_builder));

g_object_set_qdata_full (G_OBJECT (request),
quark_request_session,
Expand Down Expand Up @@ -471,21 +471,22 @@ set_pointer_barriers_done (GObject *source_object,
&results,
res,
&error))
{
{
g_dbus_error_strip_remote_error (error);
g_warning ("A backend call failed: %s", error->message);
g_clear_error (&error);
}

should_close_session = !request->exported || response != 0;

if (request->exported)
{
if (response != 0)
if (!results)
{
GVariantBuilder results_builder;

g_variant_builder_init (&results_builder, G_VARIANT_TYPE_VARDICT);
results = g_variant_builder_end (&results_builder);
results = g_variant_ref_sink (g_variant_builder_end (&results_builder));
}

xdp_dbus_request_emit_response (XDP_DBUS_REQUEST (request), response, results);
Expand All @@ -512,7 +513,7 @@ handle_set_pointer_barriers (XdpDbusInputCapture *object,
InputCaptureSession *input_capture_session;
g_autoptr(GError) error = NULL;
GVariantBuilder options_builder;
GVariant *options;
g_autoptr(GVariant) options = NULL;
Session *session;

REQUEST_AUTOLOCK (request);
Expand Down Expand Up @@ -580,7 +581,7 @@ handle_set_pointer_barriers (XdpDbusInputCapture *object,
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

options = g_variant_builder_end (&options_builder);
options = g_variant_ref_sink (g_variant_builder_end (&options_builder));

g_object_set_qdata_full (G_OBJECT (request),
quark_request_session,
Expand Down
7 changes: 3 additions & 4 deletions src/open-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,11 @@ handle_open_in_thread_func (GTask *task,

if (uri)
{
GError *error = NULL;
g_autoptr (GError) local_error = NULL;

if (!g_uri_is_valid (uri, G_URI_FLAGS_NONE, &error))
if (!g_uri_is_valid (uri, G_URI_FLAGS_NONE, &local_error))
{
g_debug ("Rejecting open request for invalid uri '%s': %s", uri, error->message);
g_clear_error (&error);
g_debug ("Rejecting open request for invalid uri '%s': %s", uri, local_error->message);

/* Reject the request */
if (request->exported)
Expand Down
6 changes: 3 additions & 3 deletions src/proxy-resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ proxy_resolver_handle_lookup (XdpDbusProxyResolver *object,
else
{
g_auto (GStrv) proxies = NULL;
GError *error = NULL;
g_autoptr (GError) error = NULL;

proxies = g_proxy_resolver_lookup (resolver->resolver, arg_uri, NULL, &error);
if (error)
g_dbus_method_invocation_take_error (invocation, error);
if (!proxies)
g_dbus_method_invocation_take_error (invocation, g_steal_pointer (&error));
else
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(^as)", proxies));
Expand Down
11 changes: 4 additions & 7 deletions src/realtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ load_all_properties (GDBusProxy *proxy)

for (guint i = 0; i < G_N_ELEMENTS (properties); ++i)
{
GVariant *result;
g_autoptr (GVariant) result = NULL;
GVariant *parameters;
GError *error = NULL;
g_autoptr (GError) error = NULL;

parameters = g_variant_new ("(ss)", "org.freedesktop.RealtimeKit1", properties[i]);
result = g_dbus_proxy_call_sync (proxy,
Expand All @@ -258,14 +258,13 @@ load_all_properties (GDBusProxy *proxy)
NULL,
&error);

if (error)
if (!result)
{
g_warning ("Failed to load RealtimeKit property: %s", error->message);
g_error_free (error);
}
else
{
GVariant *value;
g_autoptr (GVariant) value = NULL;
g_variant_get (result, "(v)", &value);

if (i == MAX_REALTIME_PRIORITY)
Expand All @@ -281,8 +280,6 @@ load_all_properties (GDBusProxy *proxy)
g_assert_not_reached ();

g_dbus_proxy_set_cached_property (proxy, properties[i], value);
g_variant_unref (value);
g_variant_unref (result);
}
}
}
Expand Down
Loading
Loading