shared-bindings: I2SOut: Ensure object is deinitialised

(or deinitialized, for those of us on this side of the pond)

Otherwise, a sequence like
```
audio = audiobusio.I2SOut(bit_clock=board.D6, word_select=board.D9, data=board.D10)
sine_wave_sample = audiocore.RawSample(sine_wave)
audio.play(sine_wave_sample, loop=True)
del audio
```
could free the memory associated with audio without stopping the
related background task.  Later, when fresh objects are allocated within
a now-freed memory region, they can get overwritten in the background
task, leading to a hard crash.

This presumably can affect multiple I2S implementations, but it was
reported against the nRF one.
This commit is contained in:
Jeff Epler 2019-11-25 09:53:55 -06:00
parent 1c6c9a3e1f
commit 5115fdaa6f

View File

@ -117,7 +117,7 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
assert_pin(data_obj, false);
const mcu_pin_obj_t *data = MP_OBJ_TO_PTR(data_obj);
audiobusio_i2sout_obj_t *self = m_new_obj(audiobusio_i2sout_obj_t);
audiobusio_i2sout_obj_t *self = m_new_obj_with_finaliser(audiobusio_i2sout_obj_t);
self->base.type = &audiobusio_i2sout_type;
common_hal_audiobusio_i2sout_construct(self, bit_clock, word_select, data, args[ARG_left_justified].u_bool);
@ -268,6 +268,7 @@ const mp_obj_property_t audiobusio_i2sout_paused_obj = {
STATIC const mp_rom_map_elem_t audiobusio_i2sout_locals_dict_table[] = {
// Methods
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&audiobusio_i2sout_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiobusio_i2sout_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiobusio_i2sout___exit___obj) },