* [9front] acme: fix leaking Plumbmsg when saving file via Put (patch)
@ 2021-11-05 12:38 igor
2021-11-05 18:47 ` cinap_lenrek
0 siblings, 1 reply; 2+ messages in thread
From: igor @ 2021-11-05 12:38 UTC (permalink / raw)
To: 9front; +Cc: igor
[-- Attachment #1: Type: text/plain, Size: 1773 bytes --]
The attached patch fixes leaking a Plumbmsg when saving a file
via Put in acme.
<snip>
To reproduce the problem:
> open acme and determine its PID (let's assume it is 181451)
cpu% leak -s 181451
src(0x002000cb); // 1
> modify a file in acme an middle click on 'Put'
cpu% leak -s 181451
src(0x002000cb); // 1
src(0x0020ebbc); // 1
src(0x0020ebcb); // 1
src(0x0020ebdd); // 1
src(0x0020ebf0); // 1
src(0x0020ec1e); // 1
src(0x0020ec39); // 1
cpu% acid 181451
/proc/181451/text:amd64 plan 9 executable
/sys/lib/acid/port
/sys/lib/acid/amd64
acid: src(0x0020ebbc)
/sys/src/cmd/acme/exec.c:678
673 f->text[i]->w->putseq = f->seq;
674 f->text[i]->w->dirty = w->dirty;
675 }
676 }
677 if(plumbsendfd >= 0){
>678 pm = emalloc(sizeof(Plumbmsg));
679 pm->src = estrdup("acme");
680 pm->dst = estrdup("put");
681 pm->wdir = estrdup(name);
682 if(p = strrchr(pm->wdir, '/'))
683 *p = '\0';
acid:
This patch ensures to always free the heap allocated Plumbsg.
After applying the patch the leak is fixed:
> open acme and determine its PID (let's assume it is 181781)
cpu% leak -s 181781
src(0x002000cb); // 1
> modify a file in acme an middle click on 'Put'
cpu% leak -s 181781
src(0x002000cb); // 1
cpu%
The leak is not observed anymore by `leak`.
---
diff ca73f673473457152d6f1b2e9030495f8dec5c49 5c955e081f444e16d208b1ba78fe742a8f0a53c7
--- a/sys/src/cmd/acme/exec.c Mon Nov 1 18:07:28 2021
+++ b/sys/src/cmd/acme/exec.c Fri Nov 5 12:27:07 2021
@@ -687,8 +687,7 @@
pm->ndata = strlen(pm->data);
if(pm->ndata < messagesize-1024)
plumbsend(plumbsendfd, pm);
- else
- plumbfree(pm);
+ plumbfree(pm);
}
fbuffree(s);
fbuffree(r);
</snap>
The patch is attached for review.
Cheers,
Igor
[-- Attachment #2: acme.put.leak.patch --]
[-- Type: text/plain, Size: 1769 bytes --]
From: Igor Böhm <igor@9lab.org>
Date: Fri, 05 Nov 2021 11:27:07 +0000
Subject: [PATCH] acme: fix leaking Plumbmsg when saving file via Put
To reproduce the problem:
> open acme and determine its PID (let's assume it is 181451)
cpu% leak -s 181451
src(0x002000cb); // 1
> modify a file in acme an middle click on 'Put'
cpu% leak -s 181451
src(0x002000cb); // 1
src(0x0020ebbc); // 1
src(0x0020ebcb); // 1
src(0x0020ebdd); // 1
src(0x0020ebf0); // 1
src(0x0020ec1e); // 1
src(0x0020ec39); // 1
cpu% acid 181451
/proc/181451/text:amd64 plan 9 executable
/sys/lib/acid/port
/sys/lib/acid/amd64
acid: src(0x0020ebbc)
/sys/src/cmd/acme/exec.c:678
673 f->text[i]->w->putseq = f->seq;
674 f->text[i]->w->dirty = w->dirty;
675 }
676 }
677 if(plumbsendfd >= 0){
>678 pm = emalloc(sizeof(Plumbmsg));
679 pm->src = estrdup("acme");
680 pm->dst = estrdup("put");
681 pm->wdir = estrdup(name);
682 if(p = strrchr(pm->wdir, '/'))
683 *p = '\0';
acid:
This patch ensures to always free the heap allocated Plumbsg. After
applying the patch the leak is fixed:
> open acme and determine its PID (let's assume it is 181781)
cpu% leak -s 181781
src(0x002000cb); // 1
> modify a file in acme an middle click on 'Put'
cpu% leak -s 181781
src(0x002000cb); // 1
cpu%
The leak is not observed anymore by `leak`.
---
diff ca73f673473457152d6f1b2e9030495f8dec5c49 5c955e081f444e16d208b1ba78fe742a8f0a53c7
--- a/sys/src/cmd/acme/exec.c Mon Nov 1 18:07:28 2021
+++ b/sys/src/cmd/acme/exec.c Fri Nov 5 12:27:07 2021
@@ -687,8 +687,7 @@
pm->ndata = strlen(pm->data);
if(pm->ndata < messagesize-1024)
plumbsend(plumbsendfd, pm);
- else
- plumbfree(pm);
+ plumbfree(pm);
}
fbuffree(s);
fbuffree(r);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [9front] acme: fix leaking Plumbmsg when saving file via Put (patch)
2021-11-05 12:38 [9front] acme: fix leaking Plumbmsg when saving file via Put (patch) igor
@ 2021-11-05 18:47 ` cinap_lenrek
0 siblings, 0 replies; 2+ messages in thread
From: cinap_lenrek @ 2021-11-05 18:47 UTC (permalink / raw)
To: 9front
Nice, there seem to be also other calls to plumbsend() that follow
the same pattern.
Thanks igor!
--
cinap
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-05 18:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 12:38 [9front] acme: fix leaking Plumbmsg when saving file via Put (patch) igor
2021-11-05 18:47 ` 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).