Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin Fix file descriptor leak. Found by cppcheck.
details: https://anonhg.NetBSD.org/src/rev/98b638af1048
branches: trunk
changeset: 760433:98b638af1048
user: wiz <wiz%NetBSD.org@localhost>
date: Tue Jan 04 23:31:29 2011 +0000
description:
Fix file descriptor leak. Found by cppcheck.
diffstat:
sbin/ccdconfig/ccdconfig.c | 6 ++++--
sbin/ldconfig/ldconfig.c | 14 ++++++++------
2 files changed, 12 insertions(+), 8 deletions(-)
diffs (82 lines):
diff -r 3fa0c9128428 -r 98b638af1048 sbin/ccdconfig/ccdconfig.c
--- a/sbin/ccdconfig/ccdconfig.c Tue Jan 04 23:29:51 2011 +0000
+++ b/sbin/ccdconfig/ccdconfig.c Tue Jan 04 23:31:29 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ccdconfig.c,v 1.49 2009/03/16 12:52:07 lukem Exp $ */
+/* $NetBSD: ccdconfig.c,v 1.50 2011/01/04 23:31:29 wiz Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1996, 1997\
The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: ccdconfig.c,v 1.49 2009/03/16 12:52:07 lukem Exp $");
+__RCSID("$NetBSD: ccdconfig.c,v 1.50 2011/01/04 23:31:29 wiz Exp $");
#endif
#include <sys/param.h>
@@ -471,9 +471,11 @@
cp = "unknown";
}
warn("ioctl (%s): %s", cp, path);
+ (void)close(fd);
return (1);
}
+ (void)close(fd);
return (0);
}
diff -r 3fa0c9128428 -r 98b638af1048 sbin/ldconfig/ldconfig.c
--- a/sbin/ldconfig/ldconfig.c Tue Jan 04 23:29:51 2011 +0000
+++ b/sbin/ldconfig/ldconfig.c Tue Jan 04 23:31:29 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldconfig.c,v 1.47 2010/05/13 17:52:12 tnozaki Exp $ */
+/* $NetBSD: ldconfig.c,v 1.48 2011/01/04 23:34:06 wiz Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ldconfig.c,v 1.47 2010/05/13 17:52:12 tnozaki Exp $");
+__RCSID("$NetBSD: ldconfig.c,v 1.48 2011/01/04 23:34:06 wiz Exp $");
#endif
@@ -467,20 +467,20 @@
if (write(fd, &hdr, sizeof(struct hints_header)) !=
sizeof(struct hints_header)) {
warn("%s", _PATH_LD_HINTS);
- goto out;
+ goto fdout;
}
if ((size_t)write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) !=
hdr.hh_nbucket * sizeof(struct hints_bucket)) {
warn("%s", _PATH_LD_HINTS);
- goto out;
+ goto fdout;
}
if (write(fd, strtab, strtab_sz) != strtab_sz) {
warn("%s", _PATH_LD_HINTS);
- goto out;
+ goto fdout;
}
if (fchmod(fd, 0444) == -1) {
warn("%s", _PATH_LD_HINTS);
- goto out;
+ goto fdout;
}
if (close(fd) != 0) {
warn("%s", _PATH_LD_HINTS);
@@ -501,6 +501,8 @@
free(blist);
free(strtab);
return 0;
+fdout:
+ (void)close(fd);
out:
free(blist);
free(strtab);
Home |
Main Index |
Thread Index |
Old Index