From 7cb71df02cbe417798067a4f68a62dcbca8be025 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 30 Nov 2016 01:58:45 -0500 Subject: mcu: Be careful to free memory allocated in C code Free steppersync, stepcompress, and commandqueue objects. Signed-off-by: Kevin O'Connor --- klippy/stepcompress.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'klippy/stepcompress.c') diff --git a/klippy/stepcompress.c b/klippy/stepcompress.c index b00dd7c3..732afe99 100644 --- a/klippy/stepcompress.c +++ b/klippy/stepcompress.c @@ -290,6 +290,17 @@ stepcompress_alloc(uint32_t max_error, uint32_t queue_step_msgid return sc; } +// Free memory associated with a 'stepcompress' object +void +stepcompress_free(struct stepcompress *sc) +{ + if (!sc) + return; + free(sc->queue); + message_queue_free(&sc->msg_queue); + free(sc); +} + // Convert previously scheduled steps into commands for the mcu static void stepcompress_flush(struct stepcompress *sc, uint64_t move_clock) @@ -573,6 +584,18 @@ steppersync_alloc(struct serialqueue *sq, struct stepcompress **sc_list return ss; } +// Free memory associated with a 'steppersync' object +void +steppersync_free(struct steppersync *ss) +{ + if (!ss) + return; + free(ss->sc_list); + free(ss->move_clocks); + serialqueue_free_commandqueue(ss->cq); + free(ss); +} + // Implement a binary heap algorithm to track when the next available // 'struct move' in the mcu will be available static void -- cgit v1.2.3-70-g09d2