[gdm/wip/rancell/g-auto: 35/35] Use g_auto for variables
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm/wip/rancell/g-auto: 35/35] Use g_auto for variables
- Date: Tue, 5 Dec 2017 03:43:15 +0000 (UTC)
commit 39190ca3b0cec51c6387f14cd2b1349aa0144ead
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Sep 28 13:16:18 2017 -0400
Use g_auto for variables
chooser/chooser-main.c | 6 +--
chooser/gdm-chooser-session.h | 2 +
common/gdm-common.c | 14 ++---
daemon/gdm-dbus-util.c | 28 +++-------
daemon/gdm-display-access-file.h | 2 +
daemon/gdm-display.c | 104 +++++++++++++-----------------------
daemon/gdm-launch-environment.c | 10 +---
daemon/gdm-launch-environment.h | 2 +
daemon/gdm-legacy-display.c | 9 +--
daemon/gdm-local-display-factory.c | 9 +--
daemon/gdm-manager.c | 14 ++----
daemon/gdm-session-worker.h | 2 +
daemon/gdm-session.c | 8 +--
daemon/gdm-session.h | 2 +
daemon/gdm-x-session.c | 16 ++----
daemon/main.c | 7 +--
daemon/session-worker-main.c | 10 +---
libgdm/gdm-client.c | 58 +++++++-------------
libgdm/gdm-client.h | 2 +
libgdm/gdm-user-switching.c | 12 ++---
20 files changed, 113 insertions(+), 204 deletions(-)
---
diff --git a/chooser/chooser-main.c b/chooser/chooser-main.c
index 6f94c62..87598e5 100644
--- a/chooser/chooser-main.c
+++ b/chooser/chooser-main.c
@@ -203,7 +203,7 @@ load_a11y (void)
int
main (int argc, char *argv[])
{
- GdmChooserSession *session;
+ g_autoptr(GdmChooserSession) session = NULL;
gboolean res;
GError *error;
@@ -242,9 +242,5 @@ main (int argc, char *argv[])
gtk_main ();
- if (session != NULL) {
- g_object_unref (session);
- }
-
return 0;
}
diff --git a/chooser/gdm-chooser-session.h b/chooser/gdm-chooser-session.h
index b6d8ccd..a53b2df 100644
--- a/chooser/gdm-chooser-session.h
+++ b/chooser/gdm-chooser-session.h
@@ -45,6 +45,8 @@ typedef struct
GObjectClass parent_class;
} GdmChooserSessionClass;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdmChooserSession, g_object_unref)
+
GType gdm_chooser_session_get_type (void);
GdmChooserSession * gdm_chooser_session_new (void);
diff --git a/common/gdm-common.c b/common/gdm-common.c
index 31fc810..c3984b6 100644
--- a/common/gdm-common.c
+++ b/common/gdm-common.c
@@ -316,8 +316,8 @@ static gboolean
create_transient_display (GDBusConnection *connection,
GError **error)
{
- GError *local_error = NULL;
- GVariant *reply;
+ g_autoptr(GError) local_error = NULL;
+ g_autoptr(GVariant) reply = NULL;
const char *value;
reply = g_dbus_connection_call_sync (connection,
@@ -332,14 +332,13 @@ create_transient_display (GDBusConnection *connection,
NULL, &local_error);
if (reply == NULL) {
g_warning ("Unable to create transient display: %s", local_error->message);
- g_propagate_error (error, local_error);
+ g_propagate_error (error, g_steal_pointer (&local_error));
return FALSE;
}
g_variant_get (reply, "(&o)", &value);
g_debug ("Started %s", value);
- g_variant_unref (reply);
return TRUE;
}
@@ -348,8 +347,8 @@ activate_session_id (GDBusConnection *connection,
const char *seat_id,
const char *session_id)
{
- GError *local_error = NULL;
- GVariant *reply;
+ g_autoptr(GError) local_error = NULL;
+ g_autoptr(GVariant) reply = NULL;
reply = g_dbus_connection_call_sync (connection,
"org.freedesktop.login1",
@@ -363,12 +362,9 @@ activate_session_id (GDBusConnection *connection,
NULL, &local_error);
if (reply == NULL) {
g_warning ("Unable to activate session: %s", local_error->message);
- g_error_free (local_error);
return FALSE;
}
- g_variant_unref (reply);
-
return TRUE;
}
diff --git a/daemon/gdm-dbus-util.c b/daemon/gdm-dbus-util.c
index b71da7f..f0c8fa7 100644
--- a/daemon/gdm-dbus-util.c
+++ b/daemon/gdm-dbus-util.c
@@ -109,9 +109,8 @@ gdm_dbus_get_pid_for_name (const char *system_bus_name,
pid_t *out_pid,
GError **error)
{
- GDBusConnection *bus;
- GVariant *reply;
- gboolean retval = FALSE;
+ g_autoptr(GDBusConnection) bus = NULL;
+ g_autoptr(GVariant) reply = NULL;
unsigned int v;
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
@@ -130,18 +129,13 @@ gdm_dbus_get_pid_for_name (const char *system_bus_name,
-1,
NULL, error);
if (reply == NULL) {
- goto out;
+ return FALSE;
}
g_variant_get (reply, "(u)", &v);
*out_pid = v;
- g_variant_unref (reply);
-
- retval = TRUE;
- out:
- g_object_unref (bus);
- return retval;
+ return TRUE;
}
gboolean
@@ -149,9 +143,8 @@ gdm_dbus_get_uid_for_name (const char *system_bus_name,
uid_t *out_uid,
GError **error)
{
- GDBusConnection *bus;
- GVariant *reply;
- gboolean retval = FALSE;
+ g_autoptr(GDBusConnection) bus = NULL;
+ g_autoptr(GVariant) reply = NULL;
unsigned int v;
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
@@ -170,16 +163,11 @@ gdm_dbus_get_uid_for_name (const char *system_bus_name,
-1,
NULL, error);
if (reply == NULL) {
- goto out;
+ return FALSE;
}
g_variant_get (reply, "(u)", &v);
*out_uid = v;
- g_variant_unref (reply);
-
- retval = TRUE;
- out:
- g_object_unref (bus);
- return retval;
+ return TRUE;
}
diff --git a/daemon/gdm-display-access-file.h b/daemon/gdm-display-access-file.h
index cc7de9e..2681e4d 100644
--- a/daemon/gdm-display-access-file.h
+++ b/daemon/gdm-display-access-file.h
@@ -55,6 +55,8 @@ struct _GdmDisplayAccessFileClass
GObjectClass parent_class;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdmDisplayAccessFile, g_object_unref)
+
enum _GdmDisplayAccessFileError
{
GDM_DISPLAY_ACCESS_FILE_ERROR_GENERAL = 0,
diff --git a/daemon/gdm-display.c b/daemon/gdm-display.c
index 1b58781..36843e5 100644
--- a/daemon/gdm-display.c
+++ b/daemon/gdm-display.c
@@ -152,13 +152,10 @@ chown_recursively (GFile *dir,
gid_t gid,
GError **error)
{
- GFile *file = NULL;
- GFileInfo *info = NULL;
- GFileEnumerator *enumerator = NULL;
- gboolean retval = FALSE;
+ g_autoptr(GFileEnumerator) enumerator = NULL;
if (chown_file (dir, uid, gid, error) == FALSE) {
- goto out;
+ return FALSE;
}
enumerator = g_file_enumerate_children (dir,
@@ -167,35 +164,31 @@ chown_recursively (GFile *dir,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL, error);
if (!enumerator) {
- goto out;
+ return FALSE;
}
- while ((info = g_file_enumerator_next_file (enumerator, NULL, error)) != NULL) {
+ while (TRUE) {
+ g_autoptr(GFileInfo) info = NULL;
+ g_autoptr(GFile) file = NULL;
+
+ info = g_file_enumerator_next_file (enumerator, NULL, error);
+ if (info == NULL) {
+ return *error == NULL;
+ }
file = g_file_get_child (dir, g_file_info_get_name (info));
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
if (chown_recursively (file, uid, gid, error) == FALSE) {
- goto out;
+ return FALSE;
}
} else if (chown_file (file, uid, gid, error) == FALSE) {
- goto out;
+ return FALSE;
}
- g_clear_object (&file);
g_clear_object (&info);
}
- if (*error) {
- goto out;
- }
-
- retval = TRUE;
-out:
- g_clear_object (&file);
- g_clear_object (&info);
- g_clear_object (&enumerator);
-
- return retval;
+ return TRUE;
}
GQuark
@@ -253,9 +246,9 @@ _create_access_file_for_user (GdmDisplay *self,
gboolean
gdm_display_create_authority (GdmDisplay *self)
{
- GdmDisplayAccessFile *access_file;
- GError *error;
- gboolean res;
+ g_autoptr(GdmDisplayAccessFile) access_file = NULL;
+ g_autoptr(GError) error = NULL;
+ gboolean res;
g_return_val_if_fail (GDM_IS_DISPLAY (self), FALSE);
g_return_val_if_fail (self->priv->access_file == NULL, FALSE);
@@ -265,7 +258,6 @@ gdm_display_create_authority (GdmDisplay *self)
if (access_file == NULL) {
g_critical ("could not create display access file: %s", error->message);
- g_error_free (error);
return FALSE;
}
@@ -278,15 +270,12 @@ gdm_display_create_authority (GdmDisplay *self)
&error);
if (! res) {
-
g_critical ("could not add display to access file: %s", error->message);
- g_error_free (error);
gdm_display_access_file_close (access_file);
- g_object_unref (access_file);
return FALSE;
}
- self->priv->access_file = access_file;
+ self->priv->access_file = g_steal_pointer (&access_file);
return TRUE;
}
@@ -311,9 +300,9 @@ gdm_display_add_user_authorization (GdmDisplay *self,
char **filename,
GError **error)
{
- GdmDisplayAccessFile *access_file;
- GError *access_file_error;
- gboolean res;
+ g_autoptr(GdmDisplayAccessFile) access_file = NULL;
+ g_autoptr(GError) access_file_error = NULL;
+ gboolean res;
int i;
XHostAddress host_entries[3];
@@ -341,7 +330,7 @@ gdm_display_add_user_authorization (GdmDisplay *self,
&access_file_error);
if (access_file == NULL) {
- g_propagate_error (error, access_file_error);
+ g_propagate_error (error, g_steal_pointer (&access_file_error));
return FALSE;
}
@@ -354,14 +343,13 @@ gdm_display_add_user_authorization (GdmDisplay *self,
g_debug ("GdmDisplay: Unable to add user authorization for %s: %s",
username,
access_file_error->message);
- g_propagate_error (error, access_file_error);
+ g_propagate_error (error, g_steal_pointer (&access_file_error));
gdm_display_access_file_close (access_file);
- g_object_unref (access_file);
return FALSE;
}
*filename = gdm_display_access_file_get_path (access_file);
- self->priv->user_access_file = access_file;
+ self->priv->user_access_file = g_steal_pointer (&access_file);
g_debug ("GdmDisplay: Added user authorization for %s: %s", username, *filename);
/* Remove access for the programs run by greeter now that the
@@ -539,9 +527,9 @@ gdm_display_real_prepare (GdmDisplay *self)
static void
look_for_existing_users_sync (GdmDisplay *self)
{
- GError *error = NULL;
- GVariant *call_result;
- GVariant *user_list;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) call_result = NULL;
+ g_autoptr(GVariant) user_list = NULL;
self->priv->accountsservice_proxy = g_dbus_proxy_new_sync (self->priv->connection,
0, NULL,
@@ -553,7 +541,7 @@ look_for_existing_users_sync (GdmDisplay *self)
if (!self->priv->accountsservice_proxy) {
g_warning ("Failed to contact accountsservice: %s", error->message);
- goto out;
+ return;
}
call_result = g_dbus_proxy_call_sync (self->priv->accountsservice_proxy,
@@ -566,15 +554,11 @@ look_for_existing_users_sync (GdmDisplay *self)
if (!call_result) {
g_warning ("Failed to list cached users: %s", error->message);
- goto out;
+ return;
}
g_variant_get (call_result, "(@ao)", &user_list);
self->priv->have_existing_user_accounts = g_variant_n_children (user_list) > 0;
- g_variant_unref (user_list);
- g_variant_unref (call_result);
-out:
- g_clear_error (&error);
}
gboolean
@@ -1360,14 +1344,8 @@ gdm_display_finalize (GObject *object)
g_clear_object (&self->priv->object_skeleton);
g_clear_object (&self->priv->connection);
g_clear_object (&self->priv->accountsservice_proxy);
-
- if (self->priv->access_file != NULL) {
- g_object_unref (self->priv->access_file);
- }
-
- if (self->priv->user_access_file != NULL) {
- g_object_unref (self->priv->user_access_file);
- }
+ g_clear_object (&self->priv->access_file);
+ g_clear_object (&self->priv->user_access_file);
if (self->priv->server_timer != NULL) {
g_timer_destroy (self->priv->server_timer);
@@ -1661,11 +1639,11 @@ gdm_display_start_greeter_session (GdmDisplay *self)
static void
chown_initial_setup_home_dir (void)
{
- GFile *dir;
- GError *error;
- char *gis_dir_path;
- char *gis_uid_path;
- char *gis_uid_contents;
+ g_autoptr(GFile) dir = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autofree gchar *gis_dir_path = NULL;
+ g_autofree gchar *gis_uid_path = NULL;
+ g_autofree gchar *gis_uid_contents = NULL;
struct passwd *pwe;
uid_t uid;
@@ -1681,27 +1659,21 @@ chown_initial_setup_home_dir (void)
NULL);
if (!g_file_get_contents (gis_uid_path, &gis_uid_contents, NULL, NULL)) {
g_warning ("Unable to read %s", gis_uid_path);
- goto out;
+ return;
}
uid = (uid_t) atoi (gis_uid_contents);
pwe = getpwuid (uid);
if (uid == 0 || pwe == NULL) {
g_warning ("UID '%s' in %s is not valid", gis_uid_contents, gis_uid_path);
- goto out;
+ return;
}
error = NULL;
dir = g_file_new_for_path (gis_dir_path);
if (!chown_recursively (dir, pwe->pw_uid, pwe->pw_gid, &error)) {
g_warning ("Failed to change ownership for %s: %s", gis_dir_path, error->message);
- g_error_free (error);
}
- g_object_unref (dir);
-out:
- g_free (gis_uid_contents);
- g_free (gis_uid_path);
- g_free (gis_dir_path);
}
void
diff --git a/daemon/gdm-launch-environment.c b/daemon/gdm-launch-environment.c
index 676ebc6..ba7ee38 100644
--- a/daemon/gdm-launch-environment.c
+++ b/daemon/gdm-launch-environment.c
@@ -305,10 +305,9 @@ on_conversation_stopped (GdmSession *session,
const char *service_name,
GdmLaunchEnvironment *launch_environment)
{
- GdmSession *conversation_session;
+ g_autoptr(GdmSession) conversation_session = NULL;
- conversation_session = launch_environment->priv->session;
- launch_environment->priv->session = NULL;
+ conversation_session = g_steal_pointer (&launch_environment->priv->session);
g_debug ("GdmLaunchEnvironment: conversation stopped");
@@ -319,7 +318,6 @@ on_conversation_stopped (GdmSession *session,
if (conversation_session != NULL) {
gdm_session_close (conversation_session);
- g_object_unref (conversation_session);
}
}
@@ -868,9 +866,7 @@ gdm_launch_environment_finalize (GObject *object)
gdm_launch_environment_stop (launch_environment);
- if (launch_environment->priv->session) {
- g_object_unref (launch_environment->priv->session);
- }
+ g_clear_object (&launch_environment->priv->session);
g_free (launch_environment->priv->command);
g_free (launch_environment->priv->user_name);
diff --git a/daemon/gdm-launch-environment.h b/daemon/gdm-launch-environment.h
index c2a09d1..fe2a3ed 100644
--- a/daemon/gdm-launch-environment.h
+++ b/daemon/gdm-launch-environment.h
@@ -63,6 +63,8 @@ typedef struct
const char *hostname);
} GdmLaunchEnvironmentClass;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdmLaunchEnvironment, g_object_unref)
+
GType gdm_launch_environment_get_type (void);
gboolean gdm_launch_environment_start (GdmLaunchEnvironment *launch_environment);
diff --git a/daemon/gdm-legacy-display.c b/daemon/gdm-legacy-display.c
index cd6259b..78e473b 100644
--- a/daemon/gdm-legacy-display.c
+++ b/daemon/gdm-legacy-display.c
@@ -93,7 +93,7 @@ static gboolean
gdm_legacy_display_prepare (GdmDisplay *display)
{
GdmLegacyDisplay *self = GDM_LEGACY_DISPLAY (display);
- GdmLaunchEnvironment *launch_environment;
+ g_autoptr(GdmLaunchEnvironment) launch_environment = NULL;
char *display_name;
char *seat_id;
gboolean doing_initial_setup = FALSE;
@@ -121,7 +121,6 @@ gdm_legacy_display_prepare (GdmDisplay *display)
}
g_object_set (self, "launch-environment", launch_environment, NULL);
- g_object_unref (launch_environment);
if (!gdm_display_create_authority (display)) {
g_warning ("Unable to set up access control for display %s",
@@ -144,8 +143,8 @@ on_server_ready (GdmServer *server,
g_debug ("GdmDisplay: could not connect to display");
gdm_display_unmanage (GDM_DISPLAY (self));
} else {
- GdmLaunchEnvironment *launch_environment;
- char *display_device;
+ g_autoptr(GdmLaunchEnvironment) launch_environment = NULL;
+ g_autofree gchar *display_device = NULL;
display_device = gdm_server_get_display_device (server);
@@ -156,8 +155,6 @@ on_server_ready (GdmServer *server,
"x11-display-device",
display_device,
NULL);
- g_clear_pointer(&display_device, g_free);
- g_clear_object (&launch_environment);
g_debug ("GdmDisplay: connected to display");
g_object_set (G_OBJECT (self), "status", GDM_DISPLAY_MANAGED, NULL);
diff --git a/daemon/gdm-local-display-factory.c b/daemon/gdm-local-display-factory.c
index b29f5ac..500a9ae 100644
--- a/daemon/gdm-local-display-factory.c
+++ b/daemon/gdm-local-display-factory.c
@@ -415,9 +415,9 @@ delete_display (GdmLocalDisplayFactory *factory,
static gboolean
gdm_local_display_factory_sync_seats (GdmLocalDisplayFactory *factory)
{
- GError *error = NULL;
- GVariant *result;
- GVariant *array;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) result = NULL;
+ g_autoptr(GVariant) array = NULL;
GVariantIter iter;
const char *seat;
@@ -434,7 +434,6 @@ gdm_local_display_factory_sync_seats (GdmLocalDisplayFactory *factory)
if (!result) {
g_warning ("GdmLocalDisplayFactory: Failed to issue method call: %s", error->message);
- g_clear_error (&error);
return FALSE;
}
@@ -462,8 +461,6 @@ gdm_local_display_factory_sync_seats (GdmLocalDisplayFactory *factory)
create_display (factory, seat, session_type, is_initial);
}
- g_variant_unref (result);
- g_variant_unref (array);
return TRUE;
}
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
index 9f06196..f8e7528 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -301,8 +301,8 @@ activate_session_id (GdmManager *manager,
const char *seat_id,
const char *session_id)
{
- GError *error = NULL;
- GVariant *reply;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) reply = NULL;
reply = g_dbus_connection_call_sync (manager->priv->connection,
"org.freedesktop.login1",
@@ -318,12 +318,9 @@ activate_session_id (GdmManager *manager,
if (reply == NULL) {
g_debug ("GdmManager: logind 'ActivateSessionOnSeat' %s raised:\n %s\n\n",
g_dbus_error_get_remote_error (error), error->message);
- g_error_free (error);
return FALSE;
}
- g_variant_unref (reply);
-
return TRUE;
}
@@ -331,8 +328,8 @@ static gboolean
session_unlock (GdmManager *manager,
const char *ssid)
{
- GError *error = NULL;
- GVariant *reply;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) reply = NULL;
g_debug ("Unlocking session %s", ssid);
@@ -350,12 +347,9 @@ session_unlock (GdmManager *manager,
if (reply == NULL) {
g_debug ("GdmManager: logind 'UnlockSession' %s raised:\n %s\n\n",
g_dbus_error_get_remote_error (error), error->message);
- g_error_free (error);
return FALSE;
}
- g_variant_unref (reply);
-
return TRUE;
}
diff --git a/daemon/gdm-session-worker.h b/daemon/gdm-session-worker.h
index 5603e80..9a2a5ef 100644
--- a/daemon/gdm-session-worker.h
+++ b/daemon/gdm-session-worker.h
@@ -48,6 +48,8 @@ typedef struct
GdmDBusWorkerSkeletonClass parent_class;
} GdmSessionWorkerClass;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdmSessionWorker, g_object_unref)
+
GType gdm_session_worker_get_type (void);
GdmSessionWorker * gdm_session_worker_new (const char *server_address,
diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
index 610ebcd..3ffce95 100644
--- a/daemon/gdm-session.c
+++ b/daemon/gdm-session.c
@@ -2184,10 +2184,10 @@ on_initialization_complete_cb (GdmDBusWorker *proxy,
{
GdmSessionConversation *conversation = user_data;
GdmSession *self;
- char *service_name;
+ const gchar *service_name;
- GError *error = NULL;
- GVariant *ret;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) ret = NULL;
ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, &error);
@@ -2210,12 +2210,10 @@ on_initialization_complete_cb (GdmDBusWorker *proxy,
service_name);
gdm_session_authenticate (self, service_name);
- g_variant_unref (ret);
} else {
g_dbus_method_invocation_return_gerror (conversation->starting_invocation, error);
report_and_stop_conversation (self, service_name, error);
- g_error_free (error);
}
g_clear_object (&conversation->starting_invocation);
diff --git a/daemon/gdm-session.h b/daemon/gdm-session.h
index a22c095..7df2cf6 100644
--- a/daemon/gdm-session.h
+++ b/daemon/gdm-session.h
@@ -113,6 +113,8 @@ typedef struct
const char *service_name);
} GdmSessionClass;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdmSession, g_object_unref)
+
GType gdm_session_get_type (void);
GdmSession *gdm_session_new (GdmSessionVerificationMode verification_mode,
diff --git a/daemon/gdm-x-session.c b/daemon/gdm-x-session.c
index 88fe96f..96a1038 100644
--- a/daemon/gdm-x-session.c
+++ b/daemon/gdm-x-session.c
@@ -377,9 +377,8 @@ update_bus_environment (State *state,
GCancellable *cancellable)
{
GVariantBuilder builder;
- GVariant *reply = NULL;
- GError *error = NULL;
- gboolean environment_updated = FALSE;
+ g_autoptr(GVariant) reply = NULL;
+ g_autoptr(GError) error = NULL;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
g_variant_builder_add (&builder, "{ss}", "DISPLAY", state->display_name);
@@ -398,17 +397,10 @@ update_bus_environment (State *state,
if (reply == NULL) {
g_debug ("could not update activation environment: %s", error->message);
- goto out;
+ return FALSE;
}
- g_variant_unref (reply);
-
- environment_updated = TRUE;
-
-out:
- g_clear_error (&error);
-
- return environment_updated;
+ return TRUE;
}
static gboolean
diff --git a/daemon/main.c b/daemon/main.c
index 4a5c549..d0010e8 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -306,9 +306,9 @@ int
main (int argc,
char **argv)
{
- GMainLoop *main_loop;
+ g_autoptr(GMainLoop) main_loop = NULL;
GOptionContext *context;
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
gboolean res;
static gboolean do_timed_exit = FALSE;
static gboolean print_version = FALSE;
@@ -336,7 +336,6 @@ main (int argc,
g_option_context_free (context);
if (! res) {
g_printerr ("Failed to parse options: %s\n", error->message);
- g_error_free (error);
return EXIT_FAILURE;
}
@@ -403,8 +402,6 @@ main (int argc,
gdm_settings_direct_shutdown ();
gdm_log_shutdown ();
- g_main_loop_unref (main_loop);
-
return EXIT_SUCCESS;
}
diff --git a/daemon/session-worker-main.c b/daemon/session-worker-main.c
index 4a3a8eb..d9a4358 100644
--- a/daemon/session-worker-main.c
+++ b/daemon/session-worker-main.c
@@ -74,9 +74,9 @@ int
main (int argc,
char **argv)
{
- GMainLoop *main_loop;
+ g_autoptr(GMainLoop) main_loop = NULL;
GOptionContext *context;
- GdmSessionWorker *worker;
+ g_autoptr(GdmSessionWorker) worker = NULL;
const char *address;
gboolean is_for_reauth;
static GOptionEntry entries [] = {
@@ -128,12 +128,6 @@ main (int argc,
g_main_loop_run (main_loop);
- if (worker != NULL) {
- g_object_unref (worker);
- }
-
- g_main_loop_unref (main_loop);
-
g_debug ("Worker finished");
return 0;
diff --git a/libgdm/gdm-client.c b/libgdm/gdm-client.c
index 6fd55bd..23eeb00 100644
--- a/libgdm/gdm-client.c
+++ b/libgdm/gdm-client.c
@@ -79,23 +79,19 @@ on_got_manager (GdmManager *manager,
GAsyncResult *result,
GSimpleAsyncResult *operation_result)
{
- GdmClient *client;
+ g_autoptr(GdmClient) client = NULL;
GdmManager *new_manager;
- GError *error;
+ g_autoptr(GError) error = NULL;
client = GDM_CLIENT (g_async_result_get_source_object (G_ASYNC_RESULT (operation_result)));
- error = NULL;
new_manager = gdm_manager_proxy_new_finish (result, &error);
if (client->priv->manager == NULL) {
client->priv->manager = new_manager;
-
} else {
g_object_ref (client->priv->manager);
g_object_unref (new_manager);
-
- g_clear_error (&error);
}
if (error != NULL) {
@@ -109,7 +105,6 @@ on_got_manager (GdmManager *manager,
g_simple_async_result_complete_in_idle (operation_result);
g_object_unref (operation_result);
- g_object_unref (client);
}
static void
@@ -118,7 +113,7 @@ get_manager (GdmClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *result;
+ g_autoptr(GSimpleAsyncResult) result = NULL;
result = g_simple_async_result_new (G_OBJECT (client),
callback,
@@ -132,7 +127,6 @@ get_manager (GdmClient *client,
(GDestroyNotify)
g_object_unref);
g_simple_async_result_complete_in_idle (result);
- g_object_unref (result);
return;
}
@@ -143,7 +137,7 @@ get_manager (GdmClient *client,
cancellable,
(GAsyncReadyCallback)
on_got_manager,
- result);
+ g_steal_pointer (&result));
}
static void
@@ -459,13 +453,12 @@ on_connected (GObject *source_object,
GAsyncResult *result,
GSimpleAsyncResult *operation_result)
{
- GDBusConnection *connection;
- GError *error;
+ g_autoptr(GDBusConnection) connection = NULL;
+ g_autoptr(GError) error = NULL;
- error = NULL;
connection = g_dbus_connection_new_for_address_finish (result, &error);
if (!connection) {
- g_simple_async_result_take_error (operation_result, error);
+ g_simple_async_result_take_error (operation_result, g_steal_pointer (&error));
g_simple_async_result_complete_in_idle (operation_result);
g_object_unref (operation_result);
return;
@@ -477,7 +470,6 @@ on_connected (GObject *source_object,
g_object_unref);
g_simple_async_result_complete_in_idle (operation_result);
g_object_unref (operation_result);
- g_object_unref (connection);
}
static void
@@ -485,21 +477,19 @@ on_session_opened (GdmManager *manager,
GAsyncResult *result,
GSimpleAsyncResult *operation_result)
{
- GdmClient *client;
+ g_autoptr(GdmClient) client = NULL;
GCancellable *cancellable;
- GError *error;
+ g_autoptr(GError) error = NULL;
client = GDM_CLIENT (g_async_result_get_source_object (G_ASYNC_RESULT (operation_result)));
- error = NULL;
if (!gdm_manager_call_open_session_finish (manager,
&client->priv->address,
result,
&error)) {
- g_simple_async_result_take_error (operation_result, error);
+ g_simple_async_result_take_error (operation_result, g_steal_pointer (&error));
g_simple_async_result_complete_in_idle (operation_result);
g_object_unref (operation_result);
- g_object_unref (client);
return;
}
@@ -511,7 +501,6 @@ on_session_opened (GdmManager *manager,
(GAsyncReadyCallback)
on_connected,
operation_result);
- g_object_unref (client);
}
static void
@@ -586,7 +575,7 @@ gdm_client_open_connection (GdmClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *operation_result;
+ g_autoptr(GSimpleAsyncResult) operation_result = NULL;
g_return_if_fail (GDM_IS_CLIENT (client));
@@ -606,7 +595,6 @@ gdm_client_open_connection (GdmClient *client,
(GDestroyNotify)
g_object_unref);
g_simple_async_result_complete_in_idle (operation_result);
- g_object_unref (operation_result);
return;
}
@@ -615,10 +603,10 @@ gdm_client_open_connection (GdmClient *client,
cancellable,
(GAsyncReadyCallback)
on_got_manager_for_opening_connection,
- operation_result);
+ g_steal_pointer (&operation_result));
} else {
client->priv->pending_opens = g_list_prepend (client->priv->pending_opens,
- operation_result);
+ g_steal_pointer (&operation_result));
}
}
@@ -910,7 +898,7 @@ gdm_client_get_user_verifier (GdmClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *operation_result;
+ g_autoptr(GSimpleAsyncResult) operation_result = NULL;
g_return_if_fail (GDM_IS_CLIENT (client));
@@ -930,7 +918,6 @@ gdm_client_get_user_verifier (GdmClient *client,
(GDestroyNotify)
g_object_unref);
g_simple_async_result_complete_in_idle (operation_result);
- g_object_unref (operation_result);
return;
}
@@ -938,7 +925,7 @@ gdm_client_get_user_verifier (GdmClient *client,
cancellable,
(GAsyncReadyCallback)
on_connection_opened_for_user_verifier,
- operation_result);
+ g_steal_pointer (&operation_result));
}
/**
@@ -1098,7 +1085,7 @@ gdm_client_get_greeter (GdmClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *operation_result;
+ g_autoptr(GSimpleAsyncResult) operation_result = NULL;
g_return_if_fail (GDM_IS_CLIENT (client));
@@ -1118,7 +1105,6 @@ gdm_client_get_greeter (GdmClient *client,
(GDestroyNotify)
g_object_unref);
g_simple_async_result_complete_in_idle (operation_result);
- g_object_unref (operation_result);
return;
}
@@ -1126,7 +1112,7 @@ gdm_client_get_greeter (GdmClient *client,
cancellable,
(GAsyncReadyCallback)
on_connection_opened_for_greeter,
- operation_result);
+ g_steal_pointer (&operation_result));
}
/**
@@ -1296,7 +1282,7 @@ gdm_client_get_remote_greeter (GdmClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *operation_result;
+ g_autoptr(GSimpleAsyncResult) operation_result = NULL;
g_return_if_fail (GDM_IS_CLIENT (client));
@@ -1316,7 +1302,6 @@ gdm_client_get_remote_greeter (GdmClient *client,
(GDestroyNotify)
g_object_unref);
g_simple_async_result_complete_in_idle (operation_result);
- g_object_unref (operation_result);
return;
}
@@ -1324,7 +1309,7 @@ gdm_client_get_remote_greeter (GdmClient *client,
cancellable,
(GAsyncReadyCallback)
on_connection_opened_for_remote_greeter,
- operation_result);
+ g_steal_pointer (&operation_result));
}
/**
@@ -1491,7 +1476,7 @@ gdm_client_get_chooser (GdmClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *operation_result;
+ g_autoptr(GSimpleAsyncResult) operation_result = NULL;
g_return_if_fail (GDM_IS_CLIENT (client));
@@ -1511,7 +1496,6 @@ gdm_client_get_chooser (GdmClient *client,
(GDestroyNotify)
g_object_unref);
g_simple_async_result_complete_in_idle (operation_result);
- g_object_unref (operation_result);
return;
}
@@ -1519,7 +1503,7 @@ gdm_client_get_chooser (GdmClient *client,
cancellable,
(GAsyncReadyCallback)
on_connection_opened_for_chooser,
- operation_result);
+ g_steal_pointer (&operation_result));
}
/**
diff --git a/libgdm/gdm-client.h b/libgdm/gdm-client.h
index 8718a2e..d23c52c 100644
--- a/libgdm/gdm-client.h
+++ b/libgdm/gdm-client.h
@@ -48,6 +48,8 @@ typedef struct
} GdmClientClass;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdmClient, g_object_unref)
+
#define GDM_CLIENT_ERROR (gdm_client_error_quark ())
typedef enum _GdmClientError {
diff --git a/libgdm/gdm-user-switching.c b/libgdm/gdm-user-switching.c
index 3d4303e..36c36df 100644
--- a/libgdm/gdm-user-switching.c
+++ b/libgdm/gdm-user-switching.c
@@ -42,8 +42,8 @@ create_transient_display (GDBusConnection *connection,
GCancellable *cancellable,
GError **error)
{
- GVariant *reply;
- const char *value;
+ g_autoptr(GVariant) reply = NULL;
+ const char *value;
reply = g_dbus_connection_call_sync (connection,
"org.gnome.DisplayManager",
@@ -63,7 +63,6 @@ create_transient_display (GDBusConnection *connection,
g_variant_get (reply, "(&o)", &value);
g_debug ("Started %s", value);
- g_variant_unref (reply);
return TRUE;
}
@@ -74,7 +73,7 @@ activate_session_id (GDBusConnection *connection,
const char *session_id,
GError **error)
{
- GVariant *reply;
+ g_autoptr(GVariant) reply = NULL;
reply = g_dbus_connection_call_sync (connection,
"org.freedesktop.login1",
@@ -91,8 +90,6 @@ activate_session_id (GDBusConnection *connection,
return FALSE;
}
- g_variant_unref (reply);
-
return TRUE;
}
@@ -264,7 +261,7 @@ gboolean
gdm_goto_login_session_sync (GCancellable *cancellable,
GError **error)
{
- GDBusConnection *connection;
+ g_autoptr(GDBusConnection) connection = NULL;
gboolean retval;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
@@ -273,6 +270,5 @@ gdm_goto_login_session_sync (GCancellable *cancellable,
retval = goto_login_session (connection, cancellable, error);
- g_object_unref (connection);
return retval;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]