From de006a4d727937555ee5dd0e2ea8223a8b71f9ec Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Sun, 23 Aug 2026 21:44:19 -0500 Subject: [PATCH 1/2] Guard POSIX pipe cleanup when popen fails Shell-less environments can make popen return null, but shared_ptr still invokes its custom deleter for a null stored pointer. Guard the pclose call so telemetry initialization returns an empty fallback identifier instead of crashing. Files changed: - lib/pal/posix/sysinfo_sources.cpp: skip pclose for a null pipe. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d7d2f27a-7339-4585-ad02-9f89ce20ef40 --- lib/pal/posix/sysinfo_sources.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pal/posix/sysinfo_sources.cpp b/lib/pal/posix/sysinfo_sources.cpp index 32a69caaa..6cd4897c5 100644 --- a/lib/pal/posix/sysinfo_sources.cpp +++ b/lib/pal/posix/sysinfo_sources.cpp @@ -114,7 +114,11 @@ static std::string Exec(const char* cmd) { std::array buffer; std::string result; - std::shared_ptr pipe(popen(cmd, "r"), pclose); + std::shared_ptr pipe(popen(cmd, "r"), [](FILE* file) { + if (file != nullptr) { + pclose(file); + } + }); if (!pipe) { // throw std::runtime_error("popen() failed!"); @@ -349,4 +353,3 @@ sysinfo_sources_impl::sysinfo_sources_impl() : sysinfo_sources() } } - From f80451e1b3a8c21dafd49e39cdd74f780e383348 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Sun, 23 Aug 2026 22:34:48 -0500 Subject: [PATCH 2/2] Use unique ownership for POSIX pipe handles Exec has sole ownership of the popen handle. unique_ptr expresses that lifetime directly and naturally skips pclose when popen returns null. Files changed:`n- lib/pal/posix/sysinfo_sources.cpp: own the pipe with a lambda-deleter unique_ptr. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>`nCopilot-Session: d7d2f27a-7339-4585-ad02-9f89ce20ef40 --- lib/pal/posix/sysinfo_sources.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/pal/posix/sysinfo_sources.cpp b/lib/pal/posix/sysinfo_sources.cpp index 6cd4897c5..28f1e3552 100644 --- a/lib/pal/posix/sysinfo_sources.cpp +++ b/lib/pal/posix/sysinfo_sources.cpp @@ -114,11 +114,8 @@ static std::string Exec(const char* cmd) { std::array buffer; std::string result; - std::shared_ptr pipe(popen(cmd, "r"), [](FILE* file) { - if (file != nullptr) { - pclose(file); - } - }); + auto close_pipe = [](FILE* file) { pclose(file); }; + std::unique_ptr pipe(popen(cmd, "r"), close_pipe); if (!pipe) { // throw std::runtime_error("popen() failed!");