9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] lock: Fix some memory leaks
@ 2023-01-21  0:17 Josiah Frentsos
  2023-01-21  7:55 ` Steve Simon
  2023-01-22 20:46 ` cinap_lenrek
  0 siblings, 2 replies; 6+ messages in thread
From: Josiah Frentsos @ 2023-01-21  0:17 UTC (permalink / raw)
  To: 9front

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])

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] lock: Fix some memory leaks
  2023-01-21  0:17 [9front] lock: Fix some memory leaks Josiah Frentsos
@ 2023-01-21  7:55 ` Steve Simon
  2023-01-22  0:36   ` Dan Cross
  2023-01-22 20:46 ` cinap_lenrek
  1 sibling, 1 reply; 6+ messages in thread
From: Steve Simon @ 2023-01-21  7:55 UTC (permalink / raw)
  To: 9front

sorry, but this patch looks very wrong.

free after return does nothing.
calling waitfor twice allocates data twice.

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.

-Steve

> 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])

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] lock: Fix some memory leaks
  2023-01-21  7:55 ` Steve Simon
@ 2023-01-22  0:36   ` Dan Cross
  2023-01-22  7:09     ` Benjamin Purcell
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Cross @ 2023-01-22  0:36 UTC (permalink / raw)
  To: 9front

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])

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] lock: Fix some memory leaks
  2023-01-22  0:36   ` Dan Cross
@ 2023-01-22  7:09     ` Benjamin Purcell
  2023-01-22  8:11       ` Steve Simon
  0 siblings, 1 reply; 6+ messages in thread
From: Benjamin Purcell @ 2023-01-22  7:09 UTC (permalink / raw)
  To: 9front

My guess would be that Steve's email client does something weird with leading whitespace.

On Sat, Jan 21, 2023, at 18:36, Dan Cross wrote:
> 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])

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] lock: Fix some memory leaks
  2023-01-22  7:09     ` Benjamin Purcell
@ 2023-01-22  8:11       ` Steve Simon
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Simon @ 2023-01-22  8:11 UTC (permalink / raw)
  To: 9front

pp

> On 22 Jan 2023, at 7:10 am, Benjamin Purcell <spew@cbza.org> wrote:
> 
> My guess would be that Steve's email client does something weird with leading whitespace.

exactly this, apologies.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] lock: Fix some memory leaks
  2023-01-21  0:17 [9front] lock: Fix some memory leaks Josiah Frentsos
  2023-01-21  7:55 ` Steve Simon
@ 2023-01-22 20:46 ` cinap_lenrek
  1 sibling, 0 replies; 6+ messages in thread
From: cinap_lenrek @ 2023-01-22 20:46 UTC (permalink / raw)
  To: 9front

applied!

--
cinap

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-01-22 20:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21  0:17 [9front] lock: Fix some memory leaks Josiah Frentsos
2023-01-21  7:55 ` Steve Simon
2023-01-22  0:36   ` Dan Cross
2023-01-22  7:09     ` Benjamin Purcell
2023-01-22  8:11       ` Steve Simon
2023-01-22 20:46 ` cinap_lenrek

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).