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>
pull/7040/head
Damien George 2021-03-16 12:40:16 +11:00
rodzic d53a6d58b0
commit 2b888aa2f3
1 zmienionych plików z 5 dodań i 0 usunięć

Wyświetl plik

@ -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);