From 23d4d12598f8253d3ff9ca158f7c3f9ddd4e3bf2 Mon Sep 17 00:00:00 2001 From: Marcin Rajwa Date: Tue, 9 Apr 2019 13:16:02 +0200 Subject: [PATCH] KPB: reclaim history buffer memory Signed-off-by: Marcin Rajwa --- src/audio/kpb.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/audio/kpb.c b/src/audio/kpb.c index 80f100b5c..a63f7f19d 100644 --- a/src/audio/kpb.c +++ b/src/audio/kpb.c @@ -71,6 +71,7 @@ static void kpb_buffer_data(struct comp_data *kpb, struct comp_buffer *source, size_t size); static size_t kpb_allocate_history_buffer(struct comp_data *kpb); static void kpb_clear_history_buffer(struct hb *buff); +static void kpb_free_history_buffer(struct hb *buff); /** * \brief Create a key phrase buffer component. @@ -254,6 +255,28 @@ static size_t kpb_allocate_history_buffer(struct comp_data *kpb) return allocated_size; } +/** + * \brief Reclaim memory of a history buffer. + * \param[in] buff - pointer to current history buffer. + * + * \return none. + */ +static void kpb_free_history_buffer(struct hb *buff) +{ + struct hb *_buff; + + /* Free history buffer/s */ + while (buff) { + /* first reclaim HB internal memory, then HB itself. */ + if (buff->start_addr) + rfree(buff->start_addr); + + _buff = buff->next; + rfree(buff); + buff = _buff; + } +} + /** * \brief Reclaim memory of a key phrase buffer. * \param[in] dev - component device pointer. @@ -266,8 +289,10 @@ static void kpb_free(struct comp_dev *dev) trace_kpb("kpb_free()"); - /* TODO: reclaim internal buffer memory */ - /* reclaim device & component data memory */ + /* Reclaim memory occupied by history buffer */ + kpb_free_history_buffer(kpb->history_buffer); + + /* Free KPB */ rfree(kpb); rfree(dev); }