diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2013-10-24 20:07:17 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2013-10-24 20:07:17 +0000 |
commit | 2e90730b31452b40205634052a81fb16da2d5ab2 (patch) | |
tree | d20057614c8aa3ad53c95dc486e35efcfb4a74b6 /usr.sbin | |
parent | 94438160c6745c7bc640026bf8db2d05960055a2 (diff) |
fix leaks on update
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/table_passwd.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/usr.sbin/smtpd/table_passwd.c b/usr.sbin/smtpd/table_passwd.c index 504dee63276..dcc9bb7e3ac 100644 --- a/usr.sbin/smtpd/table_passwd.c +++ b/usr.sbin/smtpd/table_passwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_passwd.c,v 1.2 2013/07/22 13:14:49 eric Exp $ */ +/* $OpenBSD: table_passwd.c,v 1.3 2013/10/24 20:07:16 eric Exp $ */ /* * Copyright (c) 2013 Gilles Chehade <gilles@poolp.org> @@ -81,13 +81,12 @@ static int table_passwd_update(void) { FILE *fp; - char *buf, *lbuf; + char *buf, *lbuf = NULL; size_t len; char *line; struct passwd pw; struct dict *npasswd; - /* Parse configuration */ fp = fopen(config, "r"); if (fp == NULL) @@ -99,7 +98,6 @@ table_passwd_update(void) dict_init(npasswd); - lbuf = NULL; while ((buf = fgetln(fp, &len))) { if (buf[len - 1] == '\n') buf[len - 1] = '\0'; @@ -120,6 +118,7 @@ table_passwd_update(void) dict_set(npasswd, pw.pw_name, line); } free(lbuf); + fclose(fp); /* swap passwd table and release old one*/ if (passwd) @@ -130,10 +129,16 @@ table_passwd_update(void) return (1); err: + if (fp) + fclose(fp); + free(lbuf); + /* release passwd table */ - if (npasswd) + if (npasswd) { while (dict_poproot(npasswd, NULL, (void**)&buf)) free(buf); + free(npasswd); + } return (0); } @@ -250,7 +255,7 @@ parse_passwd_entry(struct passwd *pw, const char *line) /* shell */ q = p; - if ((p = strchr(q, ':')) != NULL) + if (strchr(q, ':') != NULL) return 0; pw->pw_shell = q; |