Hello tech@,

I was reading mv.c and found two minor things in fastcopy:
1) fd leak on seldom reached code
2) At the end of the function utimes is called, while the rest of the code calls the f* variant. Consistency fix.

Index: mv.c
===================================================================
RCS file: /cvs/src/bin/mv/mv.c,v
retrieving revision 1.38
diff -u -p -r1.38 mv.c
--- mv.c        16 Jan 2015 06:39:32 -0000      1.38
+++ mv.c        7 Aug 2015 07:16:54 -0000
@@ -281,6 +281,8 @@ fastcopy(char *from, char *to, struct st
                if ((bp = malloc(blen)) == NULL) {
                        warn(NULL);
                        blen = 0;
+                       (void)close(from_fd);
+                       (void)close(to_fd);
                        return (1);
                }
        }
@@ -325,7 +327,7 @@ err:                if (unlink(to))

        TIMESPEC_TO_TIMEVAL(&tval[0], &sbp->st_atimespec);
        TIMESPEC_TO_TIMEVAL(&tval[1], &sbp->st_mtimespec);
-       if (utimes(to, tval))
+       if (futimes(to_fd, tval))
                warn("%s: set times", to);

        if (close(to_fd)) {

Reply via email to