From 593f938f68abdc94c3bc71929142365e7b01e9dc Mon Sep 17 00:00:00 2001 From: Youmin Ha Date: Tue, 13 Oct 2015 14:14:10 +0900 Subject: [PATCH] Fix memory leak The string got from tlm_seat_get_occupying_username() must be freed after used. This commit fixes the memory leak. Change-Id: If05dae74ad2027cd6c9bf81ce2d43e608d4982b9 Signed-off-by: Youmin Ha --- src/daemon/tlm-dbus-observer.c | 10 ++++++---- src/daemon/tlm-seat.c | 2 +- src/daemon/tlm-seat.h | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/daemon/tlm-dbus-observer.c b/src/daemon/tlm-dbus-observer.c index c57f690..3569ce3 100644 --- a/src/daemon/tlm-dbus-observer.c +++ b/src/daemon/tlm-dbus-observer.c @@ -419,12 +419,14 @@ _is_valid_switch_user_dbus_request( TlmDbusRequest *dbus_request, TlmSeat *seat) { - if (0 == g_strcmp0(dbus_request->username, - tlm_seat_get_occupying_username(seat))) { + gboolean ret = TRUE; + gchar *occupying_username = tlm_seat_get_occupying_username(seat); + if (0 == g_strcmp0(dbus_request->username,occupying_username)) { WARN("Cannot switch to same username"); - return FALSE; + ret = FALSE; } - return TRUE; + g_free(occupying_username); + return ret; } static gboolean diff --git a/src/daemon/tlm-seat.c b/src/daemon/tlm-seat.c index 547954f..bbe0815 100644 --- a/src/daemon/tlm-seat.c +++ b/src/daemon/tlm-seat.c @@ -455,7 +455,7 @@ tlm_seat_get_id (TlmSeat *seat) return (const gchar*) seat->priv->id; } -const gchar * +gchar * tlm_seat_get_occupying_username (TlmSeat *seat) { TlmSeatPrivate *priv = TLM_SEAT_PRIV (seat); if (!priv->session) return NULL; diff --git a/src/daemon/tlm-seat.h b/src/daemon/tlm-seat.h index b0e0567..36ff036 100644 --- a/src/daemon/tlm-seat.h +++ b/src/daemon/tlm-seat.h @@ -68,10 +68,10 @@ const gchar * tlm_seat_get_id (TlmSeat *seat); /** Get the username who occupies the seat - * @return The name of the user who holds the seat + * @return The name of the user who holds the seat (to be freed) * @return NULL if nobody occupies the seat */ -const gchar * +gchar * tlm_seat_get_occupying_username (TlmSeat* seat); gboolean @@ -83,7 +83,7 @@ tlm_seat_switch_user (TlmSeat *seat, gboolean tlm_seat_create_session (TlmSeat *seat, - const gchar *service, + const gchar *service, const gchar *username, const gchar *password, GHashTable *environment); -- 2.7.4