9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Dan Cross <crossd@gmail.com>
To: 9front@9front.org
Subject: Re: [9front] lock: Fix some memory leaks
Date: Sat, 21 Jan 2023 19:36:34 -0500	[thread overview]
Message-ID: <CAEoi9W4qXYP9A0tS0V7WQP9tdXjXBiZW_5NK370TXHG9Wm7gXA@mail.gmail.com> (raw)
In-Reply-To: <D784F665-8A94-45E0-8192-6D6BDBC1D8CD@quintile.net>

On Sat, Jan 21, 2023 at 3:52 AM Steve Simon <steve@quintile.net> wrote:
> sorry, but this patch looks very wrong.
>
> free after return does nothing.
> calling waitfor twice allocates data twice.

I've got no real context here, but a couple of brief observations: The
`return` mentioned above is conditional on some pid having an expected
value. The `free` added in this patch is for the non-return case where
the conditional does not evaluate to true.

I don't see how `waitfor` is called twice in this patch. Rather, it
appears that a call to `waitfor(...)` was replaced with
`free(waitfor(...))`

> i would also consider what happens after the waitfor() call - i have not looked at the source but i have a suspicion that lock exits, so there is no point in freeing memory anyway.

It does appear that `lock` exits here.

        - Dan C.

> > On 21 Jan 2023, at 12:18 am, Josiah Frentsos <jfrent@tilde.team> wrote:
> >
> > diff bb36ba0617b5aa8263ea9b5ece8c1a5249fedc86 uncommitted
> > --- a/sys/src/cmd/lock.c
> > +++ b/sys/src/cmd/lock.c
> > @@ -35,6 +35,7 @@
> >        }
> >        if (w->pid == pid)
> >            return w;
> > +        free(w);
> >    }
> > }
> >
> > @@ -141,7 +142,8 @@
> >        error("wait");
> >
> >    postnote(PNPROC, lckpid, "die");
> > -    waitfor(lckpid);
> > +    free(waitfor(lckpid));
> > +
> >    if(w->msg[0]){
> >        p = utfrune(w->msg, ':');
> >        if(p && p[1])

  reply	other threads:[~2023-01-22  0:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-21  0:17 Josiah Frentsos
2023-01-21  7:55 ` Steve Simon
2023-01-22  0:36   ` Dan Cross [this message]
2023-01-22  7:09     ` Benjamin Purcell
2023-01-22  8:11       ` Steve Simon
2023-01-22 20:46 ` cinap_lenrek

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=CAEoi9W4qXYP9A0tS0V7WQP9tdXjXBiZW_5NK370TXHG9Wm7gXA@mail.gmail.com \
    --to=crossd@gmail.com \
    --cc=9front@9front.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.
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).