From: Lennart Poettering Date: Wed, 18 Apr 2018 15:58:53 +0000 (+0200) Subject: sysusers: fix memory leak when /etc/passwd contains multiple identical lines X-Git-Tag: v239~382^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=43e948eea639c7072bc1aecf8522d9ba9d7c6b91;p=platform%2Fupstream%2Fsystemd.git sysusers: fix memory leak when /etc/passwd contains multiple identical lines Fixes: #8718 --- diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index b3c0546..a0d9f45 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;