summaryrefslogtreecommitdiff
path: root/src/login/logind-core.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-08-03 18:53:09 +0200
committerSven Eden <sven.eden@prydeworx.com>2018-10-29 10:18:32 +0100
commit7c0ab3a048d170b66807e8f32231878abcb93a49 (patch)
treeee22811f7c120bd264efc1402ac7cadb622f4a82 /src/login/logind-core.c
parentb51458394dfa82168ab4a94a6b3d16557a6bf93f (diff)
logind: rework Seat/Session/User object allocation and freeing a bit
Let's update things a bit to follow current practices: - User structure initialization rather than zero-initialized allocation - Always propagate proper errors from allocation functions - Use _cleanup_ for freeing objects when allocation fails half-way - Make destructors return NULL (cherry picked from commit 8c29a4570993105fecc12288596d2ee77c7f82b8)
Diffstat (limited to 'src/login/logind-core.c')
-rw-r--r--src/login/logind-core.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index db0df19e2..7e096277b 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -102,15 +102,16 @@ int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_dev
int manager_add_seat(Manager *m, const char *id, Seat **_seat) {
Seat *s;
+ int r;
assert(m);
assert(id);
s = hashmap_get(m->seats, id);
if (!s) {
- s = seat_new(m, id);
- if (!s)
- return -ENOMEM;
+ r = seat_new(&s, m, id);
+ if (r < 0)
+ return r;
}
if (_seat)
@@ -121,15 +122,16 @@ int manager_add_seat(Manager *m, const char *id, Seat **_seat) {
int manager_add_session(Manager *m, const char *id, Session **_session) {
Session *s;
+ int r;
assert(m);
assert(id);
s = hashmap_get(m->sessions, id);
if (!s) {
- s = session_new(m, id);
- if (!s)
- return -ENOMEM;
+ r = session_new(&s, m, id);
+ if (r < 0)
+ return r;
}
if (_session)