[gdm/wip/wayland-rebase: 8/12] session: Prevent memory leaks by removing strdup accessors
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm/wip/wayland-rebase: 8/12] session: Prevent memory leaks by removing strdup accessors
- Date: Fri, 14 Feb 2014 20:51:21 +0000 (UTC)
commit 21bb8862ef22ecb075fd724a26ab9229802189cd
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Feb 13 14:48:00 2014 -0500
session: Prevent memory leaks by removing strdup accessors
gdm_session_get_* dup the strings they return, but not a lot of code
frees the resulting strings. It's a lot easier to not dup the return
values and make them const char *, as they won't ever change while
some code holds onto them...
daemon/gdm-manager.c | 25 +++++++------------------
daemon/gdm-session-worker.c | 3 +--
daemon/gdm-session.c | 16 ++++++++--------
daemon/gdm-session.h | 10 +++++-----
daemon/gdm-simple-slave.c | 11 ++++-------
5 files changed, 25 insertions(+), 40 deletions(-)
---
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
index ab85a92..6faceda 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -467,7 +467,7 @@ find_session_for_user_on_seat (GdmManager *manager,
for (node = manager->priv->user_sessions; node != NULL; node = node->next) {
GdmSession *candidate_session = node->data;
- char *candidate_username, *candidate_seat_id;
+ const char *candidate_username, *candidate_seat_id;
if (candidate_session == dont_count_session)
continue;
@@ -480,14 +480,8 @@ find_session_for_user_on_seat (GdmManager *manager,
if (g_strcmp0 (candidate_username, username) == 0 &&
g_strcmp0 (candidate_seat_id, seat_id) == 0) {
- g_free (candidate_username);
- g_free (candidate_seat_id);
-
return candidate_session;
}
-
- g_free (candidate_username);
- g_free (candidate_seat_id);
}
return NULL;
@@ -570,9 +564,9 @@ switch_to_compatible_user_session (GdmManager *manager,
{
gboolean res;
gboolean ret;
- char *username;
- char *seat_id;
- char *ssid_to_activate = NULL;
+ const char *username;
+ const char *seat_id;
+ const char *ssid_to_activate = NULL;
GdmSession *existing_session;
ret = FALSE;
@@ -606,8 +600,6 @@ switch_to_compatible_user_session (GdmManager *manager,
ret = TRUE;
out:
- g_free (ssid_to_activate);
-
return ret;
}
@@ -631,7 +623,7 @@ gdm_manager_handle_open_session (GdmDBusManager *manager,
GDBusConnection *connection;
GdmDisplay *display;
GdmSession *session;
- char *address;
+ const char *address;
GPid pid;
uid_t uid, allowed_user;
@@ -679,7 +671,6 @@ gdm_manager_handle_open_session (GdmDBusManager *manager,
gdm_dbus_manager_complete_open_session (GDM_DBUS_MANAGER (manager),
invocation,
address);
- g_free (address);
return TRUE;
}
@@ -834,7 +825,7 @@ start_user_session (GdmManager *manager,
{
if (display != NULL) {
char *auth_file;
- char *username;
+ const char *username;
auth_file = NULL;
username = gdm_session_get_username (operation->session);
@@ -842,7 +833,6 @@ start_user_session (GdmManager *manager,
username,
&auth_file,
NULL);
- g_free (username);
g_assert (auth_file != NULL);
@@ -882,13 +872,12 @@ on_start_user_session (StartUserSessionOperation *operation)
destroy_start_user_session_operation (operation);
} else {
GdmDisplay *display;
- char *username;
+ const char *username;
display = get_display_for_session (operation->manager, operation->session);
username = gdm_session_get_username (operation->session);
gdm_display_stop_initial_session (display, username);
- g_free (username);
start_user_session (operation->manager, display, operation);
}
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
index 8ea5b77..772179a 100644
--- a/daemon/gdm-session-worker.c
+++ b/daemon/gdm-session-worker.c
@@ -2770,7 +2770,7 @@ reauthentication_request_new (GdmSessionWorker *worker,
{
ReauthenticationRequest *request;
const char * const * environment;
- char *address;
+ const char *address;
environment = gdm_session_worker_get_environment (worker);
@@ -2819,7 +2819,6 @@ reauthentication_request_new (GdmSessionWorker *worker,
gdm_dbus_worker_complete_start_reauthentication (GDM_DBUS_WORKER (worker),
invocation,
address);
- g_free (address);
return request;
}
diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
index 7beb8a3..7b6b5e2 100644
--- a/daemon/gdm-session.c
+++ b/daemon/gdm-session.c
@@ -2606,31 +2606,31 @@ gdm_session_start_reauthentication (GdmSession *session,
conversation);
}
-char *
+const char *
gdm_session_get_server_address (GdmSession *self)
{
g_return_val_if_fail (GDM_IS_SESSION (self), NULL);
- return g_strdup (g_dbus_server_get_client_address (self->priv->outside_server));
+ return g_dbus_server_get_client_address (self->priv->outside_server);
}
-char *
+const char *
gdm_session_get_username (GdmSession *self)
{
g_return_val_if_fail (GDM_IS_SESSION (self), NULL);
- return g_strdup (self->priv->selected_user);
+ return self->priv->selected_user;
}
-char *
+const char *
gdm_session_get_display_device (GdmSession *self)
{
g_return_val_if_fail (GDM_IS_SESSION (self), NULL);
- return g_strdup (self->priv->display_device);
+ return self->priv->display_device;
}
-char *
+const char *
gdm_session_get_display_seat_id (GdmSession *self)
{
g_return_val_if_fail (GDM_IS_SESSION (self), NULL);
@@ -2638,7 +2638,7 @@ gdm_session_get_display_seat_id (GdmSession *self)
return g_strdup (self->priv->display_seat_id);
}
-char *
+const char *
gdm_session_get_session_id (GdmSession *self)
{
GdmSessionConversation *conversation;
diff --git a/daemon/gdm-session.h b/daemon/gdm-session.h
index 33ff43a..fb190bf 100644
--- a/daemon/gdm-session.h
+++ b/daemon/gdm-session.h
@@ -105,11 +105,11 @@ void gdm_session_start_reauthentication (GdmSession *session,
GPid pid_of_caller,
uid_t uid_of_caller);
-char *gdm_session_get_server_address (GdmSession *session);
-char *gdm_session_get_username (GdmSession *session);
-char *gdm_session_get_display_device (GdmSession *session);
-char *gdm_session_get_display_seat_id (GdmSession *session);
-char *gdm_session_get_session_id (GdmSession *session);
+const char *gdm_session_get_server_address (GdmSession *session);
+const char *gdm_session_get_username (GdmSession *session);
+const char *gdm_session_get_display_device (GdmSession *session);
+const char *gdm_session_get_display_seat_id (GdmSession *session);
+const char *gdm_session_get_session_id (GdmSession *session);
gboolean gdm_session_bypasses_xsession (GdmSession *session);
void gdm_session_start_conversation (GdmSession *session,
diff --git a/daemon/gdm-simple-slave.c b/daemon/gdm-simple-slave.c
index 38ce9f9..fa9314e 100644
--- a/daemon/gdm-simple-slave.c
+++ b/daemon/gdm-simple-slave.c
@@ -225,8 +225,8 @@ out:
static void
gdm_simple_slave_grant_console_permissions (GdmSimpleSlave *slave)
{
- char *username;
- char *display_device;
+ const char *username;
+ const char *display_device;
struct passwd *passwd_entry;
username = gdm_session_get_username (slave->priv->session);
@@ -261,8 +261,8 @@ gdm_simple_slave_grant_console_permissions (GdmSimpleSlave *slave)
static void
gdm_simple_slave_revoke_console_permissions (GdmSimpleSlave *slave)
{
- char *username;
- char *display_device;
+ const char *username;
+ const char *display_device;
username = gdm_session_get_username (slave->priv->session);
display_device = gdm_session_get_display_device (slave->priv->session);
@@ -285,9 +285,6 @@ gdm_simple_slave_revoke_console_permissions (GdmSimpleSlave *slave)
g_debug ("Not calling di_devperm_logout logout for user %s, device %s",
username, display_device);
}
-
- g_free (username);
- g_free (display_device);
}
#endif /* HAVE_LOGINDEVPERM */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]