summaryrefslogtreecommitdiff
path: root/bin/ksh
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2007-08-02 10:52:11 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2007-08-02 10:52:11 +0000
commita4cbb196dd0a9cb36cafda8fc9d2fd0631b75c89 (patch)
tree497c52c13421925d6475933e30bcd338d28aa851 /bin/ksh
parent05206ed429b296ea07b5312e1b3173c9953e3caa (diff)
another memory leak fix found by coverity. from netbsd but modified.
millert@ ok.
Diffstat (limited to 'bin/ksh')
-rw-r--r--bin/ksh/exec.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c
index 0e2abc5fe78..4d3500c3260 100644
--- a/bin/ksh/exec.c
+++ b/bin/ksh/exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec.c,v 1.46 2006/04/10 14:38:59 jaredy Exp $ */
+/* $OpenBSD: exec.c,v 1.47 2007/08/02 10:52:10 fgsch Exp $ */
/*
* execute command tree
@@ -875,7 +875,13 @@ findcom(const char *name, int flags)
npath = search(name, flags & FC_DEFPATH ? def_path : path,
X_OK, &tp->u2.errno_);
if (npath) {
- tp->val.s = tp == &temp ? npath : str_save(npath, APERM);
+ if (tp == &temp) {
+ tp->val.s = npath;
+ } else {
+ tp->val.s = str_save(npath, APERM);
+ if (npath != name)
+ afree(npath, ATEMP);
+ }
tp->flag |= ISSET|ALLOC;
} else if ((flags & FC_FUNC) &&
(fpath = str_val(global("FPATH"))) != null &&