diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index b49461393..80bfa7a04 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -2620,6 +2620,9 @@ ble_gap_update_entry_free(struct ble_gap_update_entry *entry) int rc; if (entry != NULL) { +#if MYNEWT_VAL(BLE_HS_DEBUG) + memset(entry, 0xff, sizeof *entry); +#endif rc = os_memblock_put(&ble_gap_update_entry_pool, entry); BLE_HS_DBG_ASSERT_EVAL(rc == 0); } @@ -2928,8 +2931,6 @@ done: if (rc == 0) { ble_hs_timer_resched(); } else { - ble_gap_update_entry_free(entry); - /* If the l2cap_params struct is populated, the only error is that the * controller doesn't support the connection parameters request * procedure. In this case, fallback to the L2CAP update procedure. @@ -2945,6 +2946,7 @@ done: if (rc == 0) { SLIST_INSERT_HEAD(&ble_gap_update_entries, entry, next); } else { + ble_gap_update_entry_free(entry); STATS_INC(ble_gap_stats, update_fail); } ble_hs_unlock(); diff --git a/nimble/host/test/src/ble_gap_test.c b/nimble/host/test/src/ble_gap_test.c index 8471d5b70..d161ad918 100644 --- a/nimble/host/test/src/ble_gap_test.c +++ b/nimble/host/test/src/ble_gap_test.c @@ -1854,6 +1854,15 @@ ble_gap_test_util_update_l2cap(struct ble_gap_upd_params *params, TEST_ASSERT(ble_gap_dbg_update_active(2)); + /* Attempt two duplicate updates; ensure BLE_HS_EALREADY gets returned + * both times. Make sure initial update still completes successfully + * (MYNEWT-702). + */ + rc = ble_hs_test_util_conn_update(2, params, 0); + TEST_ASSERT(rc == BLE_HS_EALREADY); + rc = ble_hs_test_util_conn_update(2, params, 0); + TEST_ASSERT(rc == BLE_HS_EALREADY); + l2cap_params.itvl_min = params->itvl_min; l2cap_params.itvl_max = params->itvl_max; l2cap_params.slave_latency = params->latency;