From b5188ac17cd2c3c22d02371ac4a7606cf053af9c Mon Sep 17 00:00:00 2001 From: schwarze Date: Mon, 22 Mar 2010 19:33:19 +0000 Subject: 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 on tech@ "looks nice" deraadt@ --- usr.bin/diff/diffreg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'usr.bin/diff/diffreg.c') 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) { -- cgit v1.2.3-59-g8ed1b