Hi All,

>From NetBSD: fd leak fix, found by cppcheck.

Index: src/usr.sbin/pwd_mkdb/pwd_mkdb.c
===================================================================
RCS file: /cvs/src/usr.sbin/pwd_mkdb/pwd_mkdb.c,v
retrieving revision 1.43
diff -u -p -r1.43 pwd_mkdb.c
--- src/usr.sbin/pwd_mkdb/pwd_mkdb.c    8 Jan 2010 13:29:08 -0000       1.43
+++ src/usr.sbin/pwd_mkdb/pwd_mkdb.c    29 Dec 2013 20:11:34 -0000
@@ -375,8 +375,10 @@ cp(char *from, char *to, mode_t mode)
 
        if ((from_fd = open(from, O_RDONLY, 0)) < 0)
                error(from);
-       if ((to_fd = open(to, O_WRONLY|O_CREAT|O_EXCL, mode)) < 0)
+       if ((to_fd = open(to, O_WRONLY|O_CREAT|O_EXCL, mode)) < 0) {
+               (void)close(from_fd);
                error(to);
+       }
        while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) {
                wcount = write(to_fd, buf, rcount);
                if (rcount != wcount || wcount == -1) {

Reply via email to