From 09adb78b551ef7659fd7e8e71c337e7de81023d2 Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 11 Jul 2020 20:50:40 +0200 Subject: Fix/Workaround a memory leak each time a device connects to BLE. --- src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/libs/mynewt-nimble') diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c index 87936bd8..eb3b4c99 100644 --- a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c +++ b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c @@ -268,10 +268,16 @@ void npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg) { + // I added this 'if' because nimble seems to never delete the timers. I assume it wants to recycle them. + // This condition ensure that a new timer is created only if 'co' points to an uninitialized structure. + // If the struct contains an existing timer, no new timer is created, which prevent a significant memory leak. + // TODO Ensure that this workaround is valid and does not generate bad side-effect. + if(co->handle == NULL) { memset(co, 0, sizeof(*co)); co->handle = xTimerCreate("co", 1, pdFALSE, co, os_callout_timer_cb); co->evq = evq; ble_npl_event_init(&co->ev, ev_cb, ev_arg); + } } ble_npl_error_t -- cgit v1.2.3