diff options
| author | Quentin Carbonneaux | 2014-08-27 19:14:50 -0400 |
|---|---|---|
| committer | Quentin Carbonneaux | 2014-08-27 19:14:50 -0400 |
| commit | 4f10783d800a45dee7a3e6a1a14e14f62a2288ca (patch) | |
| tree | ba1ed36d34ba0f49acd220a29a9d578388f39ab4 | |
| parent | f64b4e9aaadbb87406fd7342e80ceda75c9e2595 (diff) | |
fix memory leak in run
| -rw-r--r-- | exec.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -418,11 +418,9 @@ run(W *w, EBuf *eb, unsigned p0) return 0; cmd = buftobytes(&eb->b, p0, p1, 0); ctyp = cmd[0]; - if (strchr("<>|", ctyp)) - cmd++; - else + if (!strchr("<>|", ctyp)) ctyp = 0; - if (ctyp != 0) { + else { s0 = eb_getmark(w->eb, SelBeg); s1 = eb_getmark(w->eb, SelEnd); if (s1 <= s0 || s0 == -1u || s1 == -1u) @@ -435,7 +433,7 @@ run(W *w, EBuf *eb, unsigned p0) close(pout[0]); argv[0] = "/bin/sh"; argv[1] = "-c"; - argv[2] = cmd; + argv[2] = &cmd[ctyp ? 1 : 0]; argv[3] = 0; /* XXX do not leak file descriptors */ dup2(pin[0], 0); @@ -444,6 +442,7 @@ run(W *w, EBuf *eb, unsigned p0) execv(argv[0], argv); die("cannot exec"); } + free(cmd); close(pin[0]); close(pout[1]); r = calloc(1, sizeof *r); |
