[gdm/gnome-3-6] Don't iterate over a NULL strv



commit e7b8721e4afefc896057b1f622a241004866e9af
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Nov 30 15:24:17 2012 -0500

    Don't iterate over a NULL strv
    
    sd_seat_get_sessions is documented as 'may return an empty array
    or NULL', so we should be careful to not crash if it _does_ return
    NULL.
    
    Coverity complained about this.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=689376

 gui/libgdm/gdm-user-switching.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gui/libgdm/gdm-user-switching.c b/gui/libgdm/gdm-user-switching.c
index 507dd27..c4342f2 100644
--- a/gui/libgdm/gdm-user-switching.c
+++ b/gui/libgdm/gdm-user-switching.c
@@ -475,11 +475,13 @@ get_login_window_session_id_for_systemd (const char  *seat_id,
         ret = TRUE;
 
 out:
-        for (i = 0; sessions[i]; i ++) {
-                free (sessions[i]);
-        }
+        if (sessions) {
+                for (i = 0; sessions[i]; i ++) {
+                        free (sessions[i]);
+                }
 
-        free (sessions);
+                free (sessions);
+        }
 
         return ret;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]