From 16592ce5145eda473bc2e60886ffb83b7a9ea23d Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 14 Dec 2016 15:02:56 +0100 Subject: [PATCH] fix(process_util): Memory leak --- src/utils/process.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/utils/process.cpp b/src/utils/process.cpp index 63cdd40d..ab1f45cb 100644 --- a/src/utils/process.cpp +++ b/src/utils/process.cpp @@ -27,17 +27,22 @@ namespace process_util { * Execute command */ void exec(char* cmd, char** args) { - execvp(cmd, args); - throw system_error("execvp() failed"); + if (cmd != nullptr) { + execvp(cmd, args); + throw system_error("execvp() failed"); + } } /** * Execute command using shell */ void exec_sh(const char* cmd) { - static const char* shell = env_util::get("SHELL", "/bin/sh").c_str(); - execlp(shell, shell, "-c", cmd, nullptr); - throw system_error("execvp() failed"); + static const string shell{env_util::get("SHELL", "/bin/sh").c_str()}; + + if (cmd != nullptr) { + execlp(shell.c_str(), shell.c_str(), "-c", cmd, nullptr); + throw system_error("execvp() failed"); + } } /**