From 04fa66ad1150d3840116ca1c54b1b4da7fad6844 Mon Sep 17 00:00:00 2001 From: Jakub Dabek Date: Wed, 5 Dec 2018 13:58:48 +0100 Subject: [PATCH] memory: fixed memory leak Fix for memory leak when freeing continuous blocks. Untill now only one block was freed since hdr->size was zeroed at every loop pass and as it was part of loop condition loop has been fired only once even if there were more than one blocks to free. Signed-off-by: Jakub Dabek --- src/lib/alloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/alloc.c b/src/lib/alloc.c index 7fd6e3dfb..91a04d2d1 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -332,6 +332,7 @@ static void free_block(void *ptr) struct block_hdr *hdr; int i; int block; + int used_blocks; heap = get_heap_from_ptr(ptr); if (!heap) { @@ -366,7 +367,9 @@ found: panic(SOF_IPC_PANIC_MEM); /* free block header and continuous blocks */ - for (i = block; i < block + hdr->size; i++) { + used_blocks = block + hdr->size; + + for (i = block; i < used_blocks; i++) { hdr = cache_to_uncache(&block_map->block[i]); hdr->size = 0; hdr->used = 0;