diff options
| author | Dan Halbert <halbert@halwitz.org> | 2020-02-21 17:36:15 -0500 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2020-02-21 17:36:15 -0500 |
| commit | f63b2c0d0c364788f7951859733e6a5ca6150e0d (patch) | |
| tree | 52f869bf7102b53489304e660c08db8630d3b900 /ports | |
| parent | 9e6a9e46da8bc9b7b44860072c8910efb2c9b77e (diff) | |
use realloc instead
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/nrf/common-hal/neopixel_write/__init__.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c index ec313d044..0a4036aae 100644 --- a/ports/nrf/common-hal/neopixel_write/__init__.c +++ b/ports/nrf/common-hal/neopixel_write/__init__.c @@ -150,18 +150,21 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout if (MP_STATE_VM(pixels_pattern_heap)) { // Old pixels_pattern_heap will be gc'd; don't free it. pixels_pattern = NULL; - MP_STATE_VM(pixels_pattern_heap) = NULL; pixels_pattern_heap_size = 0; } + // realloc routines fall back to a plain malloc if the incoming ptr is NULL. if (sd_en) { // If the soft device is enabled then we must use PWM to // transmit. This takes a bunch of memory to do so raise an // exception if we can't. - MP_STATE_VM(pixels_pattern_heap) = (uint16_t *) m_malloc(pattern_size, false); + MP_STATE_VM(pixels_pattern_heap) = + (uint16_t *) m_realloc(MP_STATE_VM(pixels_pattern_heap), pattern_size); } else { // Might return NULL. - MP_STATE_VM(pixels_pattern_heap) = (uint16_t *) m_malloc_maybe(pattern_size, false); + MP_STATE_VM(pixels_pattern_heap) = + // true means move if necessary. + (uint16_t *) m_realloc_maybe(MP_STATE_VM(pixels_pattern_heap), pattern_size, true); } if (MP_STATE_VM(pixels_pattern_heap)) { pixels_pattern_heap_size = pattern_size; |
