as a more general solution to fd leak detection, just do CLOEXEC manually
(this also allows us to see “real” leaks)
This commit is contained in:
17
eval.c
17
eval.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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
|
* string expansion
|
||||||
@ -1340,23 +1340,10 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
|
|||||||
unlink(tf->tffn);
|
unlink(tf->tffn);
|
||||||
afree(tf, ATEMP);
|
afree(tf, ATEMP);
|
||||||
} else {
|
} else {
|
||||||
#ifdef DEBUG_LEAKS
|
int ofd1, pv[2];
|
||||||
#define ofd1 e->savefd[1]
|
|
||||||
#else
|
|
||||||
int ofd1;
|
|
||||||
#endif
|
|
||||||
int pv[2];
|
|
||||||
|
|
||||||
openpipe(pv);
|
openpipe(pv);
|
||||||
shf = shf_fdopen(pv[0], SHF_RD, NULL);
|
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);
|
ofd1 = savefd(1);
|
||||||
if (pv[1] != 1) {
|
if (pv[1] != 1) {
|
||||||
ksh_dup2(pv[1], 1, false);
|
ksh_dup2(pv[1], 1, false);
|
||||||
|
12
main.c
12
main.c
@ -34,7 +34,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#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;
|
extern char **environ;
|
||||||
|
|
||||||
@ -971,6 +971,10 @@ quitenv(struct shf *shf)
|
|||||||
* Either main shell is exiting or cleanup_parents_env() was called.
|
* Either main shell is exiting or cleanup_parents_env() was called.
|
||||||
*/
|
*/
|
||||||
if (ep->oenv == NULL) {
|
if (ep->oenv == NULL) {
|
||||||
|
#ifdef DEBUG_LEAKS
|
||||||
|
int i;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ep->type == E_NONE) {
|
if (ep->type == E_NONE) {
|
||||||
/* Main shell exiting? */
|
/* Main shell exiting? */
|
||||||
#if HAVE_PERSISTENT_HISTORY
|
#if HAVE_PERSISTENT_HISTORY
|
||||||
@ -1003,8 +1007,10 @@ quitenv(struct shf *shf)
|
|||||||
x_done();
|
x_done();
|
||||||
#endif
|
#endif
|
||||||
afreeall(APERM);
|
afreeall(APERM);
|
||||||
if (tty_fd >= 0)
|
for (fd = 3; fd < NUFILE; fd++)
|
||||||
close(tty_fd);
|
if ((i = fcntl(fd, F_GETFD, 0)) != -1 &&
|
||||||
|
(i & FD_CLOEXEC))
|
||||||
|
close(fd);
|
||||||
close(2);
|
close(2);
|
||||||
close(1);
|
close(1);
|
||||||
close(0);
|
close(0);
|
||||||
|
Reference in New Issue
Block a user