All of lore.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: lvm-devel@redhat.com
Subject: [PATCH] dmeventd: remove memory leak
Date: Tue, 23 Jul 2013 12:42:39 +1000	[thread overview]
Message-ID: <20130723124239.430bdd40@notabene.brown> (raw)


If e.g. a snapshot volume is repeatly added and removed, dmeventd will
leake memory.

This is because the 'timeout' thread is not detached and is never
joined.  So the resources it uses are never freed.

This patch changes _pthread_create_smallstack to set
PTHREAD_CREATE_DETACHED if the pthread pointer passed is NULL, and
changes _register_for_timeout to pass a NULL pointer rather than a
pointer to an unused variable.

Signed-off-by: NeilBrown <neilb@suse.de>

---

Customer found this memory leak.  It can be easily seen by e.g.

while true; do
   lvcreate -n snaptest -L 900m -s /dev/vgtest/lvtest
   sleep 1
   lvremove -f /dev/vgtest/snaptest
done

and watching /proc/`pid-of dmeventd`/maps

NeilBrown

 daemons/dmeventd/dmeventd.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

--- LVM2.2.02.84.orig/daemons/dmeventd/dmeventd.c
+++ LVM2.2.02.84/daemons/dmeventd/dmeventd.c
@@ -256,12 +256,20 @@ static struct dso_data *_alloc_dso_data(
 /* Create a device monitoring thread. */
 static int _pthread_create_smallstack(pthread_t *t, void *(*fun)(void *), void *arg)
 {
+	pthread_t tmp;
 	pthread_attr_t attr;
 	pthread_attr_init(&attr);
 	/*
 	 * We use a smaller stack since it gets preallocated in its entirety
 	 */
 	pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE);
+	/*
+	 * If no-one will be waiting, we need to detach.
+	 */
+	if (!t) {
+		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+		t = &tmp;
+	}
 	return pthread_create(t, &attr, fun, arg);
 }
 
@@ -544,9 +552,7 @@ static int _register_for_timeout(struct
 	}
 
 	if (!_timeout_running) {
-		pthread_t timeout_id;
-
-		if (!(ret = -_pthread_create_smallstack(&timeout_id, _timeout_thread, NULL)))
+		if (!(ret = -_pthread_create_smallstack(NULL, _timeout_thread, NULL)))
 			_timeout_running = 1;
 	}
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20130723/020f5a59/attachment.sig>

             reply	other threads:[~2013-07-23  2:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-23  2:42 NeilBrown [this message]
2013-07-31 20:28 ` [PATCH] dmeventd: remove memory leak Brassow Jonathan

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=20130723124239.430bdd40@notabene.brown \
    --to=neilb@suse.de \
    --cc=lvm-devel@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.