Skip to content

Commit

Permalink
Fix leak in child process for SimpleCommand::handle_grep()
Browse files Browse the repository at this point in the history
  • Loading branch information
allenh1 committed Apr 24, 2018
1 parent d6789f6 commit bd4c37f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/simple_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,16 @@ void SimpleCommand::handle_ls()
void SimpleCommand::handle_grep()
{
if (arguments[0] == std::string("grep")) {
char ** temp = new char *[arguments.size() + 1];
size_t len = arguments.size() + 1;
auto t = std::shared_ptr<char *>(
new char *[len],
[=](char ** s){
for (size_t y = 0; y < len; ++y) {
free(s[y]);
}
delete[] s;
});
char ** temp = t.get();
for (size_t y = 0; y < arguments.size() - 1; ++y) {
temp[y] = strdup(arguments[y]);
}
Expand Down

0 comments on commit bd4c37f

Please sign in to comment.