diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 348f53f29..bb75e1504 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -1189,9 +1189,8 @@ int ble_gap_slave_adv_reattempt(void) rc = ble_gap_ext_adv_set_data(ble_adv_reattempt.instance, ble_adv_reattempt.data); if (rc != 0) { - os_mbuf_free_chain(ble_adv_reattempt.data); - return rc; - } + return rc; + } rc = ble_gap_ext_adv_start(ble_adv_reattempt.instance, ble_adv_reattempt.duration, ble_adv_reattempt.max_events); @@ -3863,7 +3862,8 @@ ble_gap_ext_adv_set_data(uint8_t instance, struct os_mbuf *data) ble_adv_reattempt.data = os_msys_get_pkthdr(len , 0); } - if (ble_adv_reattempt.data) { + if (ble_adv_reattempt.data && (ble_adv_reattempt.data != data)) { + os_mbuf_adj(ble_adv_reattempt.data, len); rc = os_mbuf_appendfrom(ble_adv_reattempt.data, data, 0, len); assert (rc == 0); } @@ -3881,7 +3881,15 @@ ble_gap_ext_adv_set_data(uint8_t instance, struct os_mbuf *data) ble_hs_unlock(); done: +#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT) + if (ble_adv_reattempt.data != data) { + os_mbuf_free_chain(data); + data = NULL; + } +#else os_mbuf_free_chain(data); + data = NULL; +#endif return rc; }