Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@tieto.com>
Subject: [PATCH v2] shared: Fix not calling destroy callback while clearing up handlers
Date: Thu,  9 Jan 2014 17:56:13 +0100	[thread overview]
Message-ID: <1389286573-8986-1-git-send-email-szymon.janc@gmail.com> (raw)

From: Szymon Janc <szymon.janc@tieto.com>

read/write_watch_destroy is be called after io_set_read/write_handler
exits. This was resulting in io destroy callback being NULLem before
destroy was called resulting in io destroy not being called at all.

Fix this by assigning destroy callback only if setting non-NULL
callback. destroy_watch will clean it when called.

Fix following valgrind report:

168 (120 direct, 48 indirect) bytes in 1 blocks are definitely lost in
       loss record 34 of 36
   at 0x4C2C494: calloc (in /usr/lib/valgrind/
       vgpreload_memcheck-amd64-linux.so)
   by 0x409BAE: mgmt_new (mgmt.c:372)
   by 0x409D05: mgmt_new_default (mgmt.c:469)
   by 0x40E100: test_pre_setup (android-tester.c:371)
   by 0x40AD84: start_tester (tester.c:586)
   by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
       libglib-2.0.so.0.3800.1)
   by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
   by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
       libglib-2.0.so.0.3800.1)
   by 0x40B76C: tester_run (tester.c:784)
   by 0x4034F4: main (android-tester.c:2127)
---
 src/shared/io-glib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c
index 488b1a2..77ba19e 100644
--- a/src/shared/io-glib.c
+++ b/src/shared/io-glib.c
@@ -189,10 +189,10 @@ bool io_set_read_handler(struct io *io, io_callback_func_t callback,
 	if (io->read_watch == 0)
 		return false;
 
-done:
-	io->read_callback = callback;
 	io->read_destroy = destroy;
 	io->read_data = user_data;
+done:
+	io->read_callback = callback;
 
 	return true;
 }
@@ -250,10 +250,10 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback,
 	if (io->write_watch == 0)
 		return false;
 
-done:
-	io->write_callback = callback;
 	io->write_destroy = destroy;
 	io->write_data = user_data;
+done:
+	io->write_callback = callback;
 
 	return true;
 }
-- 
1.8.5.2


             reply	other threads:[~2014-01-09 16:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-09 16:56 Szymon Janc [this message]
2014-01-09 19:11 ` [PATCH v2] shared: Fix not calling destroy callback while clearing up handlers Johan Hedberg

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=1389286573-8986-1-git-send-email-szymon.janc@gmail.com \
    --to=szymon.janc@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=szymon.janc@tieto.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox