summaryrefslogtreecommitdiffstats
path: root/usr.bin/diff/diffreg.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2010-03-22 19:33:19 +0000
committerschwarze <schwarze@openbsd.org>2010-03-22 19:33:19 +0000
commitb5188ac17cd2c3c22d02371ac4a7606cf053af9c (patch)
tree287ab49418534b6b6cd87c1d7e2759e9613a744f /usr.bin/diff/diffreg.c
parentDead functions, lint. (diff)
downloadwireguard-openbsd-b5188ac17cd2c3c22d02371ac4a7606cf053af9c.tar.xz
wireguard-openbsd-b5188ac17cd2c3c22d02371ac4a7606cf053af9c.zip
Even though this cannot happen in the diff -r case,
even though diff(1) will exit(3) soon after this mkstemp(3) failure, even though this cannot really leak anything, close the file descriptor as soon as it is not used any more to make correctness of the code more obvious. patch from Igor Zinovik <zinovik dot igor at gmail dot com> on tech@ "looks nice" deraadt@
Diffstat (limited to 'usr.bin/diff/diffreg.c')
-rw-r--r--usr.bin/diff/diffreg.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index ac0a5416bfc..d5cf4718326 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.73 2009/10/27 23:59:37 deraadt Exp $ */
+/* $OpenBSD: diffreg.c,v 1.74 2010/03/22 19:33:19 schwarze Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -514,8 +514,10 @@ opentemp(const char *file)
return (NULL);
}
- if ((ofd = mkstemp(tempfile)) < 0)
+ if ((ofd = mkstemp(tempfile)) < 0) {
+ close(ifd);
return (NULL);
+ }
unlink(tempfile);
while ((nread = read(ifd, buf, BUFSIZ)) > 0) {
if (write(ofd, buf, nread) != nread) {