Commit 8fda79cd authored by Jasper St. Pierre's avatar Jasper St. Pierre

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...
parent 7c34b118
......@@ -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;
}
......
......@@ -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;
......
......@@ -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,
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment