tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: /bin/sh redirection in 'while' loop not closed afterwards?



On Monday, at 14:28, Anthony Mallet wrote:
| I observe this strange behaviour with /bin/sh on NetBSD-5.1 and current. It
| seems that the redirection for the 'while' loop (fd 9 below) is not closed 
once
| the loop finishes:
| 
| % /bin/sh
| $ ls /proc/self/fd
| 0 1 2 3 4
| $ while false; do :; done 9</dev/null
| $ ls /proc/self/fd
| 0  1  10 2  3  4  9

Browsing through the code, I find this  (around /usr/src/bin/sh/redir.c:113)
I guess it should be "char memory[11]", shouldn't it?

void
redirect(union node *redir, int flags)
{
[...]
        char memory[10];        /* file descriptors to write to memory */

        for (i = 10 ; --i >= 0 ; )
                memory[i] = 0;


Home | Main Index | Thread Index | Old Index