From 1df0cb4093e450ab803eb4cf3ce6c6f4989a93d8 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 10 Feb 2013 21:42:16 +0000 Subject: [PATCH] =?UTF-8?q?as=20a=20more=20general=20solution=20to=20fd=20?= =?UTF-8?q?leak=20detection,=20just=20do=20CLOEXEC=20manually=20(this=20al?= =?UTF-8?q?so=20allows=20us=20to=20see=20=E2=80=9Creal=E2=80=9D=20leaks)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eval.c | 17 ++--------------- main.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/eval.c b/eval.c index e942365..ebb58ca 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.133 2013/02/10 21:08:35 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.134 2013/02/10 21:42:15 tg Exp $"); /* * string expansion @@ -1340,23 +1340,10 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED) unlink(tf->tffn); afree(tf, ATEMP); } else { -#ifdef DEBUG_LEAKS -#define ofd1 e->savefd[1] -#else - int ofd1; -#endif - int pv[2]; + int ofd1, pv[2]; openpipe(pv); shf = shf_fdopen(pv[0], SHF_RD, NULL); -#ifdef DEBUG_LEAKS - if (!e->savefd) { - e->savefd = alloc2(NUFILE, sizeof(short), ATEMP); - memset(e->savefd, 0, NUFILE * sizeof(short)); - } - /* hack to get it closed in child */ - e->savefd[pv[0]] = pv[0]; -#endif ofd1 = savefd(1); if (pv[1] != 1) { ksh_dup2(pv[1], 1, false); diff --git a/main.c b/main.c index abf902e..61b09e2 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.259 2013/02/10 21:17:07 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.260 2013/02/10 21:42:16 tg Exp $"); extern char **environ; @@ -971,6 +971,10 @@ quitenv(struct shf *shf) * Either main shell is exiting or cleanup_parents_env() was called. */ if (ep->oenv == NULL) { +#ifdef DEBUG_LEAKS + int i; +#endif + if (ep->type == E_NONE) { /* Main shell exiting? */ #if HAVE_PERSISTENT_HISTORY @@ -1003,8 +1007,10 @@ quitenv(struct shf *shf) x_done(); #endif afreeall(APERM); - if (tty_fd >= 0) - close(tty_fd); + for (fd = 3; fd < NUFILE; fd++) + if ((i = fcntl(fd, F_GETFD, 0)) != -1 && + (i & FD_CLOEXEC)) + close(fd); close(2); close(1); close(0);