Module Name:    src
Committed By:   wiz
Date:           Tue Jan  4 23:34:06 UTC 2011

Modified Files:
        src/sbin/ldconfig: ldconfig.c

Log Message:
Fix file descriptor leak. Found by cppcheck.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sbin/ldconfig/ldconfig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/ldconfig/ldconfig.c
diff -u src/sbin/ldconfig/ldconfig.c:1.47 src/sbin/ldconfig/ldconfig.c:1.48
--- src/sbin/ldconfig/ldconfig.c:1.47	Thu May 13 17:52:12 2010
+++ src/sbin/ldconfig/ldconfig.c	Tue Jan  4 23:34:06 2011
@@ -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);

Reply via email to