From 1bdccb21c47683e20e232f04125102f0f104205b Mon Sep 17 00:00:00 2001 From: "J. Caleb Wherry" <337871+calebwherry@users.noreply.github.com> Date: Fri, 6 Oct 2023 10:03:14 -0400 Subject: [PATCH] 17758: Fixes memory leak on system call on arm (#20) --- src/Amalgam/PlatformSpecific.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Amalgam/PlatformSpecific.cpp b/src/Amalgam/PlatformSpecific.cpp index 545e64ee..c9a0b452 100644 --- a/src/Amalgam/PlatformSpecific.cpp +++ b/src/Amalgam/PlatformSpecific.cpp @@ -3,6 +3,7 @@ //system headers: #include +#include #include #include #include @@ -215,7 +216,7 @@ std::string Platform_RunSystemCommand(std::string command, bool &successful_run, p = popen(command.c_str(), "r"); #endif - if(p == NULL) + if(p == nullptr) { exit_code = 0; successful_run = false; @@ -224,12 +225,13 @@ std::string Platform_RunSystemCommand(std::string command, bool &successful_run, successful_run = true; + std::array buffer; std::string stdout_data; - - //not the fastest, but robust - char ch; - while((ch = fgetc(p)) != EOF) - stdout_data.push_back(ch); + while(!feof(p)) + { + if(fgets(buffer.data(), static_cast(buffer.size()), p) != nullptr) + stdout_data += buffer.data(); + } #ifdef OS_WINDOWS exit_code = _pclose(p);