diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-04-18 17:58:53 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-04-18 18:00:05 +0200 |
commit | 43e948eea639c7072bc1aecf8522d9ba9d7c6b91 (patch) | |
tree | 79a1e210b276fd3b6f3be4442c943690c4e626d0 /src/sysusers/sysusers.c | |
parent | 2dc993722bb23e097c5567ed5a4c88f73d660503 (diff) | |
download | systemd-43e948eea639c7072bc1aecf8522d9ba9d7c6b91.tar.gz |
sysusers: fix memory leak when /etc/passwd contains multiple identical lines
Fixes: #8718
Diffstat (limited to 'src/sysusers/sysusers.c')
-rw-r--r-- | src/sysusers/sysusers.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index b3c0546461..a0d9f454e4 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -97,8 +97,8 @@ static int load_user_database(void) { return r; while ((r = fgetpwent_sane(f, &pw)) > 0) { - char *n; int k, q; + char *n; n = strdup(pw->pw_name); if (!n) @@ -112,12 +112,12 @@ static int load_user_database(void) { q = hashmap_put(database_uid, UID_TO_PTR(pw->pw_uid), n); if (q < 0 && q != -EEXIST) { - if (k < 0) + if (k <= 0) free(n); return q; } - if (q < 0 && k < 0) + if (q <= 0 && k <= 0) free(n); } return r; @@ -159,12 +159,12 @@ static int load_group_database(void) { q = hashmap_put(database_gid, GID_TO_PTR(gr->gr_gid), n); if (q < 0 && q != -EEXIST) { - if (k < 0) + if (k <= 0) free(n); return q; } - if (q < 0 && k < 0) + if (q <= 0 && k <= 0) free(n); errno = 0; |