[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Leak in BASH "named" file descriptors?
From: |
Andreas Schwab |
Subject: |
Re: Leak in BASH "named" file descriptors? |
Date: |
Thu, 28 Jan 2016 14:58:29 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Greg Wooledge <wooledg@eeg.ccf.org> writes:
> On Wed, Jan 27, 2016 at 01:18:11PM -0500, Mathieu Patenaude wrote:
>> When using "named" file descriptors inside a function, the file descriptors
>> are not automatically un-linked when the function returns, but when using
>> regular "numbered" file descriptors they are automatically "destroyed".
>
> Could not reproduce in an interactive shell, on bash 4.3.30 (Debian).
>
> $ f() { local fd; exec {fd}</dev/null; }
> $ f
> $ g() { exec 9</dev/null; }
> $ g
> $ lsof -p $$
> ...
> bash 931 wooledg 0u CHR 136,0 0t0 3 /dev/pts/0
> bash 931 wooledg 1u CHR 136,0 0t0 3 /dev/pts/0
> bash 931 wooledg 2u CHR 136,0 0t0 3 /dev/pts/0
> bash 931 wooledg 9r CHR 1,3 0t0 1028 /dev/null
> bash 931 wooledg 10r CHR 1,3 0t0 1028 /dev/null
> bash 931 wooledg 255u CHR 136,0 0t0 3 /dev/pts/0
>
> I actually ran the lsof multiple times, in between the calls to f and g.
> FD 10 was opened by f (and kept open), and FD 9 was of course opened by g
> (and kept open).
Try replacing exec with :. Redirections established with exec are
always permanent.
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
- Leak in BASH "named" file descriptors?, Mathieu Patenaude, 2016/01/27
- Re: Leak in BASH "named" file descriptors?, Greg Wooledge, 2016/01/28
- Re: Leak in BASH "named" file descriptors?,
Andreas Schwab <=
- Re: Leak in BASH "named" file descriptors?, Mathieu Patenaude, 2016/01/28
- Re: Leak in BASH "named" file descriptors?, Greg Wooledge, 2016/01/28
- Re: Leak in BASH "named" file descriptors?, Mathieu Patenaude, 2016/01/28
- Re: Leak in BASH "named" file descriptors?, Andreas Schwab, 2016/01/28
- Re: Leak in BASH "named" file descriptors?, Reuti, 2016/01/28
- Re: Leak in BASH "named" file descriptors?, Chet Ramey, 2016/01/28
- Re: Leak in BASH "named" file descriptors?, Mathieu Patenaude, 2016/01/28
Re: Leak in BASH "named" file descriptors?, Chet Ramey, 2016/01/28