2011-03-22 12:29:06

by Dmitriy Paliy

[permalink] [raw]
Subject: [PATCH 0/1 v3] Add release all sessions when adapter is switched off

Hi,

This proposal includes also comment in the code on why g_slist_free is not
used after g_slist_foreach.

Br,
Dmitriy



2011-03-23 13:09:18

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH v3] Add release all sessions when adapter is switched off

Hi Dmitriy,

On Tue, Mar 22, 2011, Dmitriy Paliy wrote:
> All sessions should be released when adapter is switched off. Then a new
> RequestSession method call always results in change from power off to power
> on such ensuring operational mode. Otherwise, it is possible to end up in
> adapter state being powered off after RequestSession succeded.
>
> g_slist_free is not called after g_slist_foreach because the list is updated
> using g_slist_remove inside of session_free, which is called for each element
> by g_slist_foreach.
> ---
> src/adapter.c | 9 +++++++++
> 1 files changed, 9 insertions(+), 0 deletions(-)

Pushed upstream. Thanks.

Johan

2011-03-22 12:29:07

by Dmitriy Paliy

[permalink] [raw]
Subject: [PATCH v3] Add release all sessions when adapter is switched off

All sessions should be released when adapter is switched off. Then a new
RequestSession method call always results in change from power off to power
on such ensuring operational mode. Otherwise, it is possible to end up in
adapter state being powered off after RequestSession succeded.

g_slist_free is not called after g_slist_foreach because the list is updated
using g_slist_remove inside of session_free, which is called for each element
by g_slist_foreach.
---
src/adapter.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index cc4f43e..691b963 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2507,6 +2507,15 @@ static void set_mode_complete(struct btd_adapter *adapter)

DBG("");

+ /*
+ * g_slist_free is not called after g_slist_foreach because the list is
+ * updated using g_slist_remove in session_remove which is called by
+ * session_free, which is called for each element by g_slist_foreach.
+ */
+ if (adapter->mode == MODE_OFF)
+ g_slist_foreach(adapter->mode_sessions, (GFunc) session_free,
+ NULL);
+
if (adapter->pending_mode == NULL)
return;

--
1.7.1