2014-12-09 08:40:24

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 1/2] attrib/gatt.c: Fix for attrib ref

This patch makes sure that attrib instance will not disappear while
reading characteristic
---
attrib/gatt.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index f8ff2a5..0e633f7 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -673,6 +673,8 @@ static void read_long_destroy(gpointer user_data)
if (__sync_sub_and_fetch(&long_read->ref, 1) > 0)
return;

+ g_attrib_unref(long_read->attrib);
+
if (long_read->buffer != NULL)
g_free(long_read->buffer);

@@ -776,7 +778,7 @@ guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
if (long_read == NULL)
return 0;

- long_read->attrib = attrib;
+ long_read->attrib = g_attrib_ref(attrib);
long_read->func = func;
long_read->user_data = user_data;
long_read->handle = handle;
@@ -785,9 +787,10 @@ guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
plen = enc_read_req(handle, buf, buflen);
id = g_attrib_send(attrib, 0, buf, plen, read_char_helper,
long_read, read_long_destroy);
- if (id == 0)
+ if (id == 0) {
+ g_attrib_unref(long_read->attrib);
g_free(long_read);
- else {
+ } else {
__sync_fetch_and_add(&long_read->ref, 1);
long_read->id = id;
}
--
1.8.4



2014-12-10 08:40:51

by Lukasz Rymanowski

[permalink] [raw]
Subject: Re: [PATCH 1/2] attrib/gatt.c: Fix for attrib ref

Hi Johan,

On 10 December 2014 at 09:18, Johan Hedberg <[email protected]> wrote:
> Hi Lukasz,
>
> On Tue, Dec 09, 2014, Lukasz Rymanowski wrote:
>> On 9 December 2014 at 09:40, Lukasz Rymanowski
>> <[email protected]> wrote:
>> > This patch makes sure that attrib instance will not disappear while
>> > reading characteristic
>>
>> Just noticed that there is small issue in the commit msg. Should be
>> "attrib/gatt" instead of "attrib/gatt.c" :) Please fix when pushing or
>> let me know so I will send v2.
>
> I fixed the commit message myself.
Thanks

\Lukasz

Both patches are now upstream.
> Thanks.
>
> Johan

2014-12-10 08:18:58

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 1/2] attrib/gatt.c: Fix for attrib ref

Hi Lukasz,

On Tue, Dec 09, 2014, Lukasz Rymanowski wrote:
> On 9 December 2014 at 09:40, Lukasz Rymanowski
> <[email protected]> wrote:
> > This patch makes sure that attrib instance will not disappear while
> > reading characteristic
>
> Just noticed that there is small issue in the commit msg. Should be
> "attrib/gatt" instead of "attrib/gatt.c" :) Please fix when pushing or
> let me know so I will send v2.

I fixed the commit message myself. Both patches are now upstream.
Thanks.

Johan

2014-12-09 08:44:24

by Lukasz Rymanowski

[permalink] [raw]
Subject: Re: [PATCH 1/2] attrib/gatt.c: Fix for attrib ref

Hi,

On 9 December 2014 at 09:40, Lukasz Rymanowski
<[email protected]> wrote:
> This patch makes sure that attrib instance will not disappear while
> reading characteristic

Just noticed that there is small issue in the commit msg. Should be
"attrib/gatt" instead of "attrib/gatt.c" :) Please fix when pushing or
let me know so I will send v2.

\Lukasz
> ---
> attrib/gatt.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/attrib/gatt.c b/attrib/gatt.c
> index f8ff2a5..0e633f7 100644
> --- a/attrib/gatt.c
> +++ b/attrib/gatt.c
> @@ -673,6 +673,8 @@ static void read_long_destroy(gpointer user_data)
> if (__sync_sub_and_fetch(&long_read->ref, 1) > 0)
> return;
>
> + g_attrib_unref(long_read->attrib);
> +
> if (long_read->buffer != NULL)
> g_free(long_read->buffer);
>
> @@ -776,7 +778,7 @@ guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
> if (long_read == NULL)
> return 0;
>
> - long_read->attrib = attrib;
> + long_read->attrib = g_attrib_ref(attrib);
> long_read->func = func;
> long_read->user_data = user_data;
> long_read->handle = handle;
> @@ -785,9 +787,10 @@ guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
> plen = enc_read_req(handle, buf, buflen);
> id = g_attrib_send(attrib, 0, buf, plen, read_char_helper,
> long_read, read_long_destroy);
> - if (id == 0)
> + if (id == 0) {
> + g_attrib_unref(long_read->attrib);
> g_free(long_read);
> - else {
> + } else {
> __sync_fetch_and_add(&long_read->ref, 1);
> long_read->id = id;
> }
> --
> 1.8.4
>

2014-12-09 08:40:25

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 2/2] attrib/gatt: Minor coding style fix

---
attrib/gatt.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 0e633f7..b4be25a 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -942,7 +942,6 @@ guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
return g_attrib_send(attrib, 0, buf, plen, func, user_data, NULL);
}

-
static void desc_discovered_cb(guint8 status, const guint8 *ipdu,
guint16 iplen, gpointer user_data)
{
--
1.8.4