Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/extattrctl Fix fd leaks. Found by cppcheck.



details:   https://anonhg.NetBSD.org/src/rev/398887c3a1ab
branches:  trunk
changeset: 760394:398887c3a1ab
user:      wiz <wiz%NetBSD.org@localhost>
date:      Tue Jan 04 09:28:44 2011 +0000

description:
Fix fd leaks. Found by cppcheck.
While here, fix typo in warning message.

diffstat:

 usr.sbin/extattrctl/extattrctl.c |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (50 lines):

diff -r 362f19fbc9d2 -r 398887c3a1ab usr.sbin/extattrctl/extattrctl.c
--- a/usr.sbin/extattrctl/extattrctl.c  Tue Jan 04 09:25:21 2011 +0000
+++ b/usr.sbin/extattrctl/extattrctl.c  Tue Jan 04 09:28:44 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extattrctl.c,v 1.2 2009/04/15 06:01:01 lukem Exp $     */
+/*     $NetBSD: extattrctl.c,v 1.3 2011/01/04 09:28:44 wiz Exp $       */
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -153,7 +153,7 @@
        uef.uef_version = rw32(UFS_EXTATTR_VERSION);
        uef.uef_size = rw32(atoi(argv[0]));
        if (write(i, &uef, sizeof(uef)) != sizeof(uef)) {
-               warn("unable to write arribute file header");
+               warn("unable to write attribute file header");
                error = -1;
        } else if (fs_path != NULL) {
                easize = (sizeof(uef) + uef.uef_size) *
@@ -170,6 +170,7 @@
                        easize -= wlen;
                }
        }
+       close(i);
        if (error == -1) {
                unlink(argv[1]);
                return (-1);
@@ -197,6 +198,7 @@
        i = read(fd, &uef, sizeof(uef));
        if (i != sizeof(uef)) {
                warn("unable to read attribute file header");
+               (void)close(fd);
                return (-1);
        }
 
@@ -204,6 +206,7 @@
                needswap = 1;
                if (rw32(uef.uef_magic) != UFS_EXTATTR_MAGIC) {
                        fprintf(stderr, "%s: bad magic\n", argv[0]);
+                       (void)close(fd);
                        return (-1);
                }
        }
@@ -217,6 +220,7 @@
        printf("%s: version %u, size %u, byte-order: %s\n",
            argv[0], rw32(uef.uef_version), rw32(uef.uef_size), bo);
 
+       close(fd);
        return (0);
 }
 



Home | Main Index | Thread Index | Old Index