summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandmarti1424 <andmarti@gmail.com>2015-08-05 09:57:53 -0300
committerandmarti1424 <andmarti@gmail.com>2015-08-05 09:57:53 -0300
commite1b569b5be4e1b6132b07c3b2db6d96da73f02d1 (patch)
tree13d207422ab57dd5df26236a19dd5491628124cf
parent479d2905d61dad17d6da17bc6e4543f0c1055690 (diff)
Fixed memory leak after split call. Changed error calls to scerror
-rw-r--r--src/exec.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/exec.c b/src/exec.c
index 62df8df..b469e0a 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -6,9 +6,11 @@
#include <sys/wait.h> // for wait
#include "macros.h"
+#include "conf.h"
#include "color.h"
#include "utils/string.h"
#include "screen.h"
+#include "sc.h"
int exec_cmd (char * line) {
int waitres;
@@ -18,7 +20,7 @@ int exec_cmd (char * line) {
int my_pipe[2];
if (pipe(my_pipe) == -1) {
- error("Error creating pipe");
+ scerror("Error creating pipe");
getchar();
reset_prog_mode();
refresh();
@@ -28,7 +30,7 @@ int exec_cmd (char * line) {
pid_t child_id = fork();
if (child_id == -1) {
- error("Fork error");
+ scerror("Fork error");
getchar();
reset_prog_mode();
refresh();
@@ -41,10 +43,17 @@ int exec_cmd (char * line) {
dup2(my_pipe[1], 1); // redirect stdout
char * l = line;
+ int j;
l = rtrim(ltrim(line, ' '), ' ');
char ** param = split(l, ' ', 1);
execvp(param[0], param);
+ for (j=0; param[j]; j++) {
+ free(param[j]);
+ }
+ free(param);
+ param = NULL;
+
printf("Error executing command. ");
exit(-1);