diff options
author | Damien George <damien@micropython.org> | 2021-03-16 12:40:16 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-03-16 13:55:45 +1100 |
commit | 2b888aa2f346b52b16fbefbea6a2d9d8085d8ff1 (patch) | |
tree | e9505190dd15251a2cb1b8982eec765539b4cc3c | |
parent | d53a6d58b04e524e4ec5ee937a15cc3932f8ee2f (diff) |
extmod/modbluetooth: Free temp arrays in gatts register services.
This helps to reduce memory fragmentation, by freeing the heap data as soon
as it is not needed. It also helps the compiler keeps a reference to the
beginning of both arrays, which need to be traceable by the GC (otherwise
some compilers may optimise this reference to something else).
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r-- | extmod/modbluetooth.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 269493f0a..e379a8c6a 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -619,6 +619,11 @@ STATIC mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t } result->items[i] = MP_OBJ_FROM_PTR(service_handles); } + + // Free temporary arrays. + m_del(uint16_t *, handles, len); + m_del(size_t, num_handles, len); + return MP_OBJ_FROM_PTR(result); } STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_register_services_obj, bluetooth_ble_gatts_register_services); |