Close some file descriptor leaks in pw

MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D8245
This commit is contained in:
Alan Somers 2016-10-21 20:17:19 +00:00
parent 38fb20e2ac
commit 07c4accca8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=307752
3 changed files with 8 additions and 0 deletions

View File

@ -34,6 +34,7 @@ static const char rcsid[] =
#include <libutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "pwupd.h"
@ -73,8 +74,10 @@ gr_update(struct group * grp, char const * group)
}
if (gr_copy(pfd, tfd, gr, old_gr) == -1) {
gr_fini();
close(tfd);
err(1, "gr_copy()");
}
close(tfd);
if (gr_mkdb() == -1) {
gr_fini();
err(1, "gr_mkdb()");

View File

@ -34,6 +34,7 @@ static const char rcsid[] =
#include <err.h>
#include <pwd.h>
#include <libutil.h>
#include <unistd.h>
#include "pw.h"
@ -63,8 +64,10 @@ pw_nisupdate(const char * path, struct passwd * pwd, char const * user)
}
if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
pw_fini();
close(tfd);
err(1, "pw_copy()");
}
close(tfd);
if (chmod(pw_tempname(), 0644) == -1)
err(1, "chmod()");
if (rename(pw_tempname(), path) == -1)

View File

@ -111,8 +111,10 @@ pw_update(struct passwd * pwd, char const * user)
}
if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
pw_fini();
close(tfd);
err(1, "pw_copy()");
}
close(tfd);
/*
* in case of deletion of a user, the whole database
* needs to be regenerated