zsh-workers
 help / color / mirror / code / Atom feed
From: "Timothée Mazzucotelli" <timothee.mazzucotelli@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: Feature request: ZSH_XTRACEFD variable
Date: Sat, 5 Sep 2020 11:24:32 +0200	[thread overview]
Message-ID: <CAD8ZDTqdgLZKwptGSEmwaToM_1F_fCC_c6A7MDMnv-mZtE+T7w@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Ytqm7CSOctbFRgHNwqSH46pEWyM9WjFWJUiXQku8N+pQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1972 bytes --]

Thank you very much Daniel for this great explanation
on what leaking a FILE (or a fd) means. It's much clearer now.

From what I understand, the code for the ZSH_XTRACEFD feature
will then not leak any file descriptor itself.

Based on the man pages:

> The *fdopen*() function associates a stream with the existing file
descriptor, *fd*. [...]
> The file descriptor is not dup'ed, and will be closed when the stream
created by *fdopen*() is closed.

The user is the one creating the file descriptor initially,
and all Zsh does is assigning it to the xtrerr variable.

> xtrerr = fdopen(fd, "w");

Zsh should not close the file descriptor itself.
As stated previously, it should be the user's choice and responsibility
to close the file descriptors they have opened.

If, however, the stream associated to the fd by fdopen allocates memory,
then not closing that stream and assigning another value to xtrerr would
indeed cause a memory leak.
In that case, and now that I understand Bart's answer under the light of
your explanation,
we could fdopen a duplicate of the fd instead,
so we can close both the duplicated fd and its associated stream, fixing
the memory leak.

We could use the valgrind test suite to make sure there's a memory leak or
not,
unfortunately I did not manage to have it working on my computer
(there were a lot of reported leaks when there should not have been any,
see previous messages).

Timothée

On Fri, Sep 4, 2020 at 9:54 PM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Fri, Sep 4, 2020 at 12:49 PM Daniel Shahaf <d.s@daniel.shahaf.name>
> wrote:
> >
> > zsh: cannot moved fd 3: too many open files
> >
> > P.S.  The quoted error message is ungrammatical.
>
> That is supposed to say "cannot movefd fd 3" ... movefd being the name
> of the function ... someone has done a spell-checking pass over the
> error messages and fixed a "mistake" that wasn't actually a mistake?
>
>

[-- Attachment #2: Type: text/html, Size: 3129 bytes --]

  reply	other threads:[~2020-09-05  9:25 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17 15:08 Timothée Mazzucotelli
2019-05-18  7:55 ` Stephane Chazelas
2019-05-20 10:34   ` Stephane Chazelas
2019-07-21 15:08     ` Timothée Mazzucotelli
2019-07-21 15:22       ` Peter Stephenson
2019-07-31 19:40         ` Timothée Mazzucotelli
2019-07-31 19:45           ` Timothée Mazzucotelli
2019-07-31 21:12             ` Sebastian Gniazdowski
2019-08-13  9:14           ` Peter Stephenson
2019-08-13 15:38           ` Peter Stephenson
2019-09-10 22:19             ` Timothée Mazzucotelli
2019-09-11  8:45               ` Peter Stephenson
2020-04-19 10:30             ` Timothée Mazzucotelli
2020-04-20 14:09               ` Peter Stephenson
2020-05-02 18:02                 ` Timothée Mazzucotelli
2020-05-02 21:15                   ` Bart Schaefer
2020-05-03  0:06                     ` Daniel Shahaf
2020-05-03  4:43                       ` Roman Perepelitsa
2020-05-03 16:21                         ` Daniel Shahaf
2020-05-03 19:54                         ` Peter Stephenson
2020-05-03 21:06                           ` Daniel Shahaf
2020-05-04  8:35                             ` Peter Stephenson
2020-05-05  0:03                               ` Daniel Shahaf
2020-05-05 16:36                                 ` Timothée Mazzucotelli
2020-05-05 16:47                                   ` Peter Stephenson
2020-05-05 22:19                                     ` Bart Schaefer
2020-09-03 13:51                                       ` Timothée Mazzucotelli
2020-09-04 19:48                                         ` Daniel Shahaf
2020-09-04 19:53                                           ` Bart Schaefer
2020-09-05  9:24                                             ` Timothée Mazzucotelli [this message]
2020-05-05 22:11                                   ` Bart Schaefer
2020-05-03  6:01                       ` Stephane Chazelas
2020-05-03  7:07                         ` Stephane Chazelas
2020-05-03 17:30                   ` Peter Stephenson
2020-05-03 21:23                     ` Daniel Shahaf
2020-05-04  8:26                       ` Peter Stephenson
2020-05-05 20:50               ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAD8ZDTqdgLZKwptGSEmwaToM_1F_fCC_c6A7MDMnv-mZtE+T7w@mail.gmail.com \
    --to=timothee.mazzucotelli@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).