unposted: add debug code to zclose()

This commit is contained in:
Peter Stephenson 2010-02-22 11:35:13 +00:00
parent 7977ce0747
commit 48315b019b
2 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,8 @@
2010-02-22 Peter Stephenson <pws@csr.com>
* unposted: Src/utils.c: Add a debug test for trapping bad uses of
fdtable when closing fd's in zclose().
* 27721: Src/compat.c [with unnecessary test removed], Src/exec.c,
Src/system.h, Src/utils.c: update zopenmax() not to examine huge
numbers of file descriptors; only call it at initialisation;
@ -12810,5 +12813,5 @@
*****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.4912 $
* $Revision: 1.4913 $
*****************************************************

View File

@ -1,3 +1,4 @@
/*
* utils.c - miscellaneous utilities
*
@ -1704,6 +1705,14 @@ mod_export int
zclose(int fd)
{
if (fd >= 0) {
/*
* We sometimes zclose() an fd twice where the second
* time is a catch-all in case there was a failure using
* the fd. This is harmless but we need to trap it
* for the error check here.
*/
DPUTS2(fd > max_zsh_fd && fdtable[fd] != FDT_UNUSED,
"BUG: fd is %d, max_zsh_fd is %d", fd, max_zsh_fd);
fdtable[fd] = FDT_UNUSED;
while (max_zsh_fd > 0 && fdtable[max_zsh_fd] == FDT_UNUSED)
max_zsh_fd--;