[igt-dev] [PATCH i-g-t] lib/igt_core: Fix closing random handles on failure.
Maarten Lankhorst
maarten.lankhorst at linux.intel.com
Thu Mar 22 16:56:21 UTC 2018
When opening fds we never check for errors correctly,
so fix error handling so at least we don't possibly
close random fds.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
lib/igt_core.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 5092a3f035c7..9fd6ddf6184d 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -2317,16 +2317,16 @@ int igt_system_quiet(const char *command)
/* redirect */
if ((nullfd = open("/dev/null", O_WRONLY)) == -1)
- goto err;
+ goto err_ret;
if ((stdout_fd_copy = dup(STDOUT_FILENO)) == -1)
- goto err;
+ goto err_null;
if ((stderr_fd_copy = dup(STDERR_FILENO)) == -1)
- goto err;
+ goto err_out;
if (dup2(nullfd, STDOUT_FILENO) == -1)
- goto err;
+ goto err_close;
if (dup2(nullfd, STDERR_FILENO) == -1)
- goto err;
+ goto err_close;
/* See igt_system() for the reason for suspending the signal helper. */
igt_suspend_signal_helper();
@@ -2338,9 +2338,9 @@ int igt_system_quiet(const char *command)
/* restore */
if (dup2(stdout_fd_copy, STDOUT_FILENO) == -1)
- goto err;
+ goto err_close;
if (dup2(stderr_fd_copy, STDERR_FILENO) == -1)
- goto err;
+ goto err_close;
close(stdout_fd_copy);
close(stderr_fd_copy);
@@ -2349,10 +2349,12 @@ int igt_system_quiet(const char *command)
return WEXITSTATUS(status);
err:
igt_resume_signal_helper();
-
+err_close:
close(stderr_fd_copy);
+err_out:
close(stdout_fd_copy);
+err_null:
close(nullfd);
-
+err_ret:
return -1;
}
--
2.16.2
More information about the igt-dev
mailing list