Skip to content

Commit

Permalink
17758: Fixes memory leak on system call on arm (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebwherry authored Oct 6, 2023
1 parent de4d331 commit 1bdccb2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Amalgam/PlatformSpecific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//system headers:
#include <algorithm>
#include <array>
#include <cctype>
#include <codecvt>
#include <cstdio>
Expand Down Expand Up @@ -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;
Expand All @@ -224,12 +225,13 @@ std::string Platform_RunSystemCommand(std::string command, bool &successful_run,

successful_run = true;

std::array<char, 128> 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<int>(buffer.size()), p) != nullptr)
stdout_data += buffer.data();
}

#ifdef OS_WINDOWS
exit_code = _pclose(p);
Expand Down

0 comments on commit 1bdccb2

Please sign in to comment.