Fix memory leak 02/49402/3
authorYoumin Ha <youmin.ha@samsung.com>
Tue, 13 Oct 2015 05:14:10 +0000 (14:14 +0900)
committerSuchang Woo <suchang.woo@samsung.com>
Tue, 13 Oct 2015 08:28:01 +0000 (01:28 -0700)
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 <youmin.ha@samsung.com>
src/daemon/tlm-dbus-observer.c
src/daemon/tlm-seat.c
src/daemon/tlm-seat.h

index c57f690..3569ce3 100644 (file)
@@ -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
index 547954f..bbe0815 100644 (file)
@@ -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;
index b0e0567..36ff036 100644 (file)
@@ -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);