[-- 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);