From 7627f77bb9f7264c2423fe1302046ffa0d2d58b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 17:07:28 +0000 Subject: [PATCH] Refine env var helper in tptp frontend --- src/cmd_context/tptp_frontend.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cmd_context/tptp_frontend.cpp b/src/cmd_context/tptp_frontend.cpp index 103a4c88f6..ccc73bde43 100644 --- a/src/cmd_context/tptp_frontend.cpp +++ b/src/cmd_context/tptp_frontend.cpp @@ -1780,12 +1780,17 @@ class tptp_parser { return path; } - static bool try_getenv(char const* name, std::string& value) { + static bool get_env_var(char const* name, std::string& value) { #ifdef _WIN32 char* buffer = nullptr; size_t len = 0; errno_t err = ::_dupenv_s(&buffer, &len, name); - if (err != 0 || !buffer) + if (err != 0) { + if (buffer) + std::free(buffer); + return false; + } + if (!buffer) return false; value.assign(buffer); std::free(buffer); @@ -1807,7 +1812,7 @@ class tptp_parser { if (file_exists(local)) return local; // Try TPTP environment variable (standard TPTP convention) std::string root; - if (try_getenv("TPTP", root)) { + if (get_env_var("TPTP", root)) { std::string env = normalize_path(root + "/" + name); if (file_exists(env)) return env; }