diff options
author | Lukasz Rymanowski <lukasz.rymanowski@tieto.com> | 2014-12-09 09:40:24 +0100 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2014-12-10 10:18:12 +0200 |
commit | 1010aca5607465825c7491c5be2663d5d02accb7 (patch) | |
tree | 79512bd88aad7c552e2859177c2ee921e6a150a2 /attrib | |
parent | 215fe573fc15ad0d6d513495421845398b08e4af (diff) | |
download | bluez-1010aca5607465825c7491c5be2663d5d02accb7.tar.gz |
attrib/gatt: Fix for attrib ref
This patch makes sure that attrib instance will not disappear while
reading characteristic
Diffstat (limited to 'attrib')
-rw-r--r-- | attrib/gatt.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/attrib/gatt.c b/attrib/gatt.c index f8ff2a548..0e633f7da 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; } |