From 6999454853575bfbc7cb92bc41b9a03cc67249e7 Mon Sep 17 00:00:00 2001 From: Haoran Peng Date: Sat, 22 Mar 2025 01:30:48 +0000 Subject: [PATCH] Fix issues #103 and #104 --- subprocess.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/subprocess.hpp b/subprocess.hpp index 10c3a87..24fa303 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -1630,11 +1630,13 @@ inline void Popen::execute_process() noexcept(false) try { char err_buf[SP_MAX_ERR_BUF_SIZ] = {0,}; - int read_bytes = util::read_atmost_n( - fdopen(err_rd_pipe, "r"), - err_buf, - SP_MAX_ERR_BUF_SIZ); - close(err_rd_pipe); + FILE* err_fp = fdopen(err_rd_pipe, "r"); + if (!err_fp) { + close(err_rd_pipe); + throw OSError("fdopen failed", errno); + } + int read_bytes = util::read_atmost_n(err_fp, err_buf, SP_MAX_ERR_BUF_SIZ); + fclose(err_fp); if (read_bytes || strlen(err_buf)) { // Call waitpid to reap the child process