From fcf24ae387abebeb6269159a0b8509e9fcdad775 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 16 Feb 2023 15:40:40 -0500 Subject: [PATCH] [BUGFIX] chunk_alloc pinned buffer if there weren't previous chunks new buffer was pinned without being unpinned Change-Id: Ia45bc0eb67673e8df5154447d9116fcd4c147f6b --- firmware/chunk_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/firmware/chunk_alloc.c b/firmware/chunk_alloc.c index 30959e393d..fd2eb2a772 100644 --- a/firmware/chunk_alloc.c +++ b/firmware/chunk_alloc.c @@ -85,6 +85,7 @@ bool chunk_realloc(struct chunk_alloc_header *hdr, new_chunk = get_chunk_array(ctx, new_handle); /* ensure all chunks data is zeroed, we depend on it */ memset(new_chunk, 0, CHUNK_ARRSZ(max_chunks)); + put_chunk_array(ctx, new_chunk); } if (hdr->chunk_handle > 0) /* handle existing chunk */ { @@ -92,10 +93,11 @@ bool chunk_realloc(struct chunk_alloc_header *hdr, old_chunk = get_chunk_array(ctx, hdr->chunk_handle); - if (new_chunk != NULL) /* copy any valid old chunks to new */ + if (new_handle > 0) /* copy any valid old chunks to new */ { min_chunk = MIN(max_chunks, hdr->current + 1); logf("%s copying %ld chunks", __func__, min_chunk); + new_chunk = get_chunk_array(ctx, new_handle); memcpy(new_chunk, old_chunk, CHUNK_ARRSZ(min_chunk)); put_chunk_array(ctx, new_chunk); }