[gdm] session: Prevent memory leaks by removing strdup accessors
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm] session: Prevent memory leaks by removing strdup accessors
- Date: Sat, 15 Feb 2014 01:55:18 +0000 (UTC)
commit 8fda79cda9b8a89ddcfe3a95436c2b92699d1869
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-session-worker.c | 3 +-
daemon/gdm-session.c | 16 +++++++-------
daemon/gdm-session.h | 10 ++++----
daemon/gdm-simple-slave.c | 43 ++++++++++++++-----------------------
daemon/gdm-slave.c | 3 +-
daemon/gdm-slave.h | 10 ++++----
daemon/gdm-xdmcp-chooser-slave.c | 10 ++++----
7 files changed, 41 insertions(+), 54 deletions(-)
---
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
index a664ebd..7c2e004 100644
--- a/daemon/gdm-session-worker.c
+++ b/daemon/gdm-session-worker.c
@@ -2758,7 +2758,7 @@ reauthentication_request_new (GdmSessionWorker *worker,
{
ReauthenticationRequest *request;
const char * const * environment;
- char *address;
+ const char *address;
environment = gdm_session_worker_get_environment (worker);
@@ -2807,7 +2807,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 a58368d..86a8328 100644
--- a/daemon/gdm-simple-slave.c
+++ b/daemon/gdm-simple-slave.c
@@ -252,8 +252,8 @@ on_session_started (GdmSession *session,
int pid,
GdmSimpleSlave *slave)
{
- char *username;
- char *session_id;
+ const char *username;
+ const char *session_id;
g_debug ("GdmSimpleSlave: session started %d", pid);
@@ -261,14 +261,12 @@ on_session_started (GdmSession *session,
session_id = gdm_session_get_session_id (session);
g_object_set (GDM_SLAVE (slave), "session-id", session_id, NULL);
- g_free (session_id);
/* Run the PreSession script. gdmslave suspends until script has terminated */
username = gdm_session_get_username (slave->priv->session);
if (username != NULL) {
gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR "/PreSession", username);
}
- g_free (username);
/* FIXME: should we do something here?
* Note that error return status from PreSession script should
@@ -282,8 +280,8 @@ on_session_started (GdmSession *session,
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);
@@ -318,8 +316,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);
@@ -342,9 +340,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 */
@@ -376,14 +371,13 @@ static gboolean
add_user_authorization (GdmSimpleSlave *slave,
char **filename)
{
- char *username;
+ const char *username;
gboolean ret;
username = gdm_session_get_username (slave->priv->session);
ret = gdm_slave_add_user_authorization (GDM_SLAVE (slave),
username,
filename);
- g_free (username);
return ret;
}
@@ -435,8 +429,8 @@ static gboolean
switch_to_and_unlock_session (GdmSimpleSlave *slave,
gboolean fail_if_already_switched)
{
- char *username;
- char *session_id;
+ const char *username;
+ const char *session_id;
gboolean res;
username = gdm_session_get_username (slave->priv->session);
@@ -446,8 +440,6 @@ switch_to_and_unlock_session (GdmSimpleSlave *slave,
/* try to switch to an existing session */
res = gdm_slave_switch_to_user_session (GDM_SLAVE (slave), username, session_id,
fail_if_already_switched);
- g_free (username);
- g_free (session_id);
return res;
}
@@ -455,7 +447,7 @@ switch_to_and_unlock_session (GdmSimpleSlave *slave,
static void
stop_greeter (GdmSimpleSlave *slave)
{
- char *username;
+ const char *username;
gboolean script_successful;
g_debug ("GdmSimpleSlave: Stopping greeter");
@@ -476,7 +468,6 @@ stop_greeter (GdmSimpleSlave *slave)
} else {
script_successful = TRUE;
}
- g_free (username);
if (!script_successful) {
g_debug ("GdmSimpleSlave: PostLogin script unsuccessful");
@@ -1554,11 +1545,11 @@ gdm_simple_slave_run (GdmSimpleSlave *slave)
}
static gboolean
-gdm_simple_slave_open_session (GdmSlave *slave,
- GPid pid_of_caller,
- uid_t uid_of_caller,
- char **address,
- GError **error)
+gdm_simple_slave_open_session (GdmSlave *slave,
+ GPid pid_of_caller,
+ uid_t uid_of_caller,
+ const char **address,
+ GError **error)
{
GdmSimpleSlave *self = GDM_SIMPLE_SLAVE (slave);
uid_t allowed_user;
@@ -1582,7 +1573,6 @@ gdm_simple_slave_open_session (GdmSlave *slave,
}
*address = gdm_session_get_server_address (self->priv->session);
-
return TRUE;
}
@@ -1694,7 +1684,7 @@ gdm_simple_slave_stop (GdmSlave *slave)
(GDestroyNotify) g_free);
if (self->priv->session_is_running) {
- char *username;
+ const char *username;
/* Run the PostSession script. gdmslave suspends until script
* has terminated
@@ -1703,7 +1693,6 @@ gdm_simple_slave_stop (GdmSlave *slave)
if (username != NULL) {
gdm_slave_run_script (slave, GDMCONFDIR "/PostSession", username);
}
- g_free (username);
#ifdef HAVE_LOGINDEVPERM
gdm_simple_slave_revoke_console_permissions (self);
diff --git a/daemon/gdm-slave.c b/daemon/gdm-slave.c
index b1ba04f..a592ab0 100644
--- a/daemon/gdm-slave.c
+++ b/daemon/gdm-slave.c
@@ -1681,7 +1681,7 @@ handle_open_session (GdmDBusSlave *skeleton,
{
GError *error;
GdmSlaveClass *slave_class;
- char *address;
+ const char *address;
slave_class = GDM_SLAVE_GET_CLASS (slave);
if (slave_class->open_session == NULL) {
@@ -1705,7 +1705,6 @@ handle_open_session (GdmDBusSlave *skeleton,
gdm_dbus_slave_complete_open_session (skeleton, invocation, address);
- g_free (address);
return TRUE;
}
diff --git a/daemon/gdm-slave.h b/daemon/gdm-slave.h
index 9808433..c442806 100644
--- a/daemon/gdm-slave.h
+++ b/daemon/gdm-slave.h
@@ -50,11 +50,11 @@ typedef struct
gboolean (*start) (GdmSlave *slave);
gboolean (*stop) (GdmSlave *slave);
- gboolean (*open_session) (GdmSlave *slave,
- GPid pid_of_caller,
- uid_t uid_of_caller,
- char **address,
- GError **error);
+ gboolean (*open_session) (GdmSlave *slave,
+ GPid pid_of_caller,
+ uid_t uid_of_caller,
+ const char **address,
+ GError **error);
void (*open_reauthentication_channel) (GdmSlave *slave,
const char *username,
diff --git a/daemon/gdm-xdmcp-chooser-slave.c b/daemon/gdm-xdmcp-chooser-slave.c
index 0a90130..53baf9a 100644
--- a/daemon/gdm-xdmcp-chooser-slave.c
+++ b/daemon/gdm-xdmcp-chooser-slave.c
@@ -346,11 +346,11 @@ gdm_xdmcp_chooser_slave_stop (GdmSlave *slave)
}
static gboolean
-gdm_xdmcp_chooser_slave_open_session (GdmSlave *slave,
- GPid pid_of_caller,
- uid_t uid_of_caller,
- char **address,
- GError **error)
+gdm_xdmcp_chooser_slave_open_session (GdmSlave *slave,
+ GPid pid_of_caller,
+ uid_t uid_of_caller,
+ const char **address,
+ GError **error)
{
GdmXdmcpChooserSlave *self = GDM_XDMCP_CHOOSER_SLAVE (slave);
GdmSession *session;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]