linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [PATCH obexd v2 6/6] client: Remove transfer from queue before callback
Date: Thu,  3 May 2012 10:28:30 +0200	[thread overview]
Message-ID: <1336033710-2471-6-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1336033710-2471-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

It is safer to remove the transfer from the internal queue (including
session->p) before calling the transfer callback. This makes sure the
callback will not manipulate the session in a way that the transfer is
removed more than once.

This was previously protected with session->p->id != 0 checks, but once
the new callbacks have been adopted in session API, this logic can be
removed.
---
 client/session.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/client/session.c b/client/session.c
index b994080..3a8807b 100644
--- a/client/session.c
+++ b/client/session.c
@@ -497,12 +497,13 @@ void obc_session_shutdown(struct obc_session *session)
 						"Session closed by user");
 
 	if (session->p != NULL && session->p->id != 0) {
-		if (session->p->func)
-			session->p->func(session, session->p->transfer, err,
-							session->p->data);
-
-		pending_request_free(session->p);
+		p = session->p;
 		session->p = NULL;
+
+		if (p->func)
+			p->func(session, p->transfer, err, p->data);
+
+		pending_request_free(p);
 	}
 
 	while ((p = g_queue_pop_head(session->queue))) {
@@ -836,9 +837,8 @@ static void session_terminate_transfer(struct obc_session *session,
 
 		p = match->data;
 		g_queue_delete_link(session->queue, match);
-	}
-
-	p->id = 0;
+	} else
+		session->p = NULL;
 
 	obc_session_ref(session);
 
@@ -847,10 +847,8 @@ static void session_terminate_transfer(struct obc_session *session,
 
 	pending_request_free(p);
 
-	if (p == session->p) {
-		session->p = NULL;
+	if (session->p == NULL)
 		session_process_queue(session);
-	}
 
 	obc_session_unref(session);
 }
-- 
1.7.7.6


  parent reply	other threads:[~2012-05-03  8:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-03  8:28 [PATCH obexd v2 1/6] client: Minor buffer access API changes Mikel Astiz
2012-05-03  8:28 ` [PATCH obexd v2 2/6] client: Avoid GObex dependency from transfer.h Mikel Astiz
2012-05-03  8:28 ` [PATCH obexd v2 3/6] client: Give transfer pointer in session callbacks Mikel Astiz
2012-05-03  8:28 ` [PATCH obexd v2 4/6] client: Use new session callback style in modules Mikel Astiz
2012-05-03  8:28 ` [PATCH obexd v2 5/6] client: Remove deprecated part of session API Mikel Astiz
2012-05-03  8:28 ` Mikel Astiz [this message]
2012-05-03  9:32 ` [PATCH obexd v2 1/6] client: Minor buffer access API changes Luiz Augusto von Dentz

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=1336033710-2471-6-git-send-email-mikel.astiz.oss@gmail.com \
    --to=mikel.astiz.oss@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mikel.astiz@bmw-carit.de \
    /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).