diff options
Diffstat (limited to 'src/sd-login.c')
-rw-r--r-- | src/sd-login.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/sd-login.c b/src/sd-login.c index b670d18266..a0a56c4952 100644 --- a/src/sd-login.c +++ b/src/sd-login.c @@ -481,34 +481,39 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui if (uids && t) { char *w, *state; size_t l; - unsigned i = 0; FOREACH_WORD(w, l, t, state) n++; - b = new(uid_t, n); - if (!b) { - strv_free(a); - return -ENOMEM; - } + if (n == 0) + b = NULL; + else { + unsigned i = 0; - FOREACH_WORD(w, l, t, state) { - char *k; - - k = strndup(w, l); - if (!k) { - free(t); - free(b); + b = new(uid_t, n); + if (!b) { strv_free(a); return -ENOMEM; } - r = parse_uid(k, b + i); - free(k); - if (r < 0) - continue; + FOREACH_WORD(w, l, t, state) { + char *k; - i++; + k = strndup(w, l); + if (!k) { + free(t); + free(b); + strv_free(a); + return -ENOMEM; + } + + r = parse_uid(k, b + i); + free(k); + if (r < 0) + continue; + + i++; + } } } |