Fix a regression in closing a file descriptor if no --output was given

This commit is contained in:
Petr Písař 2020-11-16 17:49:57 +01:00
parent bbd427858e
commit 71b1dd06b6
2 changed files with 17 additions and 9 deletions

View File

@ -1,30 +1,34 @@
From 95b6dd923e176f0c42646e64cc9f22fb67a12b8f Mon Sep 17 00:00:00 2001
From: Ed Santiago <santiago@redhat.com>
Date: Fri, 6 Nov 2020 20:06:24 -0700
From 6a5c4499aab677d19157c7adcf598d14267283c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Mon, 16 Nov 2020 17:45:04 +0100
Subject: [PATCH] Close outfp before exec
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When called with --outfile, we open an output file to which
we log timing results. Close that descriptor in the child
fork before exec'ing the process to be timed.
Signed-off-by: Ed Santiago <santiago@redhat.com>
Reported-by: Ed Santiago <santiago@redhat.com>
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
src/time.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/time.c b/src/time.c
index 53904c9..9c7d287 100644
index f76265a..2f2b702 100644
--- a/src/time.c
+++ b/src/time.c
@@ -813,6 +813,8 @@ run_command (cmd, resp)
@@ -738,6 +738,8 @@ run_command (cmd, resp)
error (EXIT_CANCELED, errno, "cannot fork");
else if (pid == 0)
{ /* If child. */
+ if (outfp != NULL)
+ if (outfp != stderr)
+ fclose(outfp);
/* Don't cast execvp arguments; that causes errors on some systems,
versus merely warnings if the cast is left off. */
execvp (cmd[0], cmd);
--
2.26.2
2.25.4

View File

@ -1,7 +1,7 @@
Summary: A GNU utility for monitoring a program's use of system resources
Name: time
Version: 1.9
Release: 11%{?dist}
Release: 12%{?dist}
# src/time.c: GPLv3+
# COPYING: GPLv3 text
# doc/time.texi: GFDL
@ -96,6 +96,10 @@ rm -f $RPM_BUILD_ROOT%{_infodir}/dir
# time(1) manual page lives in man-pages package, bug #1612294.
%changelog
* Mon Nov 16 2020 Petr Pisar <ppisar@redhat.com> - 1.9-12
- Fix a regression in closing a file descriptor if no --output was given
(bug #1898138)
* Wed Nov 11 2020 Petr Pisar <ppisar@redhat.com> - 1.9-11
- Do not leak a file descriptor of the --output argument to a command