File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ int common_pipe::open(const std::string& cmd, char mode)
96
96
int common_pipe::close (int *exit_code)
97
97
{
98
98
if (!opened ())
99
- return report (EINVAL, " common_pipe::close " );
99
+ return 0 ; // nothing to do
100
100
// Close the pipe to process:
101
101
fclose (file_);
102
102
file_ = nullptr ;
@@ -128,6 +128,8 @@ int common_pipe::close(int *exit_code)
128
128
129
129
int common_pipe::open (const std::string &cmd, char mode)
130
130
{
131
+ if (opened ())
132
+ close (); // prevent resource leak
131
133
constexpr auto READ = 0u ;
132
134
constexpr auto WRITE = 1u ;
133
135
int fd[2 ];
@@ -170,7 +172,7 @@ int common_pipe::open(const std::string &cmd, char mode)
170
172
int common_pipe::close (int *exit_code)
171
173
{
172
174
if (!opened ())
173
- return 0 ;
175
+ return 0 ; // nothing to do
174
176
::fclose (file_);
175
177
file_ = nullptr ;
176
178
while (::waitpid (pid, exit_code, 0 ) == -1 ) {
You can’t perform that action at this time.
0 commit comments