diff --git a/src/util/piped_process.cpp b/src/util/piped_process.cpp index e3345c19c18..f5b028ae2f6 100644 --- a/src/util/piped_process.cpp +++ b/src/util/piped_process.cpp @@ -277,10 +277,10 @@ piped_processt::piped_processt( dup2(pipe_output[1], STDOUT_FILENO); dup2(pipe_output[1], STDERR_FILENO); - // Create a char** for the arguments (all the contents of commandvec - // except the first element, i.e. the command itself). - char **args = - reinterpret_cast(malloc((commandvec.size()) * sizeof(char *))); + // Create a char** for the arguments plus a NULL terminator (by convention, + // the first "argument" is the command itself) + char **args = reinterpret_cast( + malloc((commandvec.size() + 1) * sizeof(char *))); // Add all the arguments to the args array of char *. unsigned long i = 0; while(i < commandvec.size())