From 51409732d0e647661915fde0b15323005be7c9e8 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 22 Sep 2009 09:17:05 +0000 Subject: 27284: better use of movefd() --- Src/exec.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'Src/exec.c') diff --git a/Src/exec.c b/Src/exec.c index ca9cf0f4d..2263bd640 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1958,14 +1958,19 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag, if (varid) { /* fd will be over 10, don't touch mfds */ fd1 = movefd(fd2); - fdtable[fd1] = FDT_EXTERNAL; - setiparam(varid, (zlong)fd1); - /* - * If setting the parameter failed, close the fd else - * it will leak. - */ - if (errflag) - zclose(fd1); + if (fd1 == -1) { + zerr("cannot moved fd %d: %e", fd2, errno); + return; + } else { + fdtable[fd1] = FDT_EXTERNAL; + setiparam(varid, (zlong)fd1); + /* + * If setting the parameter failed, close the fd else + * it will leak. + */ + if (errflag) + zclose(fd1); + } } else if (!mfds[fd1] || unset(MULTIOS)) { if(!mfds[fd1]) { /* starting a new multio */ mfds[fd1] = (struct multio *) zhalloc(sizeof(struct multio)); -- cgit 1.4.1