9front - general discussion about 9front
 help / color / mirror / Atom feed
From: igor@9lab.org
To: 9front@9front.org
Cc: igor@9lab.org
Subject: [9front] acme: fix leaking Plumbmsg when saving file via Put (patch)
Date: Fri, 05 Nov 2021 13:38:43 +0100	[thread overview]
Message-ID: <1737E7F68C9D369216A501E5CD2D3D7B@9lab.org> (raw)

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

             reply	other threads:[~2021-11-05 12:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 12:38 igor [this message]
2021-11-05 18:47 ` 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=1737E7F68C9D369216A501E5CD2D3D7B@9lab.org \
    --to=igor@9lab.org \
    --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).