From 9c61e28d9b9faf6bd8b4e9b8d28ed79b441fbeb6 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 5 Jun 2020 17:51:38 +0200 Subject: block processor: add an internal common cleanup function Signed-off-by: David Oberhollenzer --- lib/sqfs/block_processor/common.c | 16 ++++++++++++++++ lib/sqfs/block_processor/internal.h | 2 ++ lib/sqfs/block_processor/serial.c | 9 +-------- lib/sqfs/block_processor/winpthread.c | 4 +--- 4 files changed, 20 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c index 6171632..11cbd51 100644 --- a/lib/sqfs/block_processor/common.c +++ b/lib/sqfs/block_processor/common.c @@ -270,6 +270,22 @@ fail_outblk: return err; } +void block_processor_cleanup(sqfs_block_processor_t *base) +{ + sqfs_block_t *it; + + if (base->frag_block != NULL) + release_old_block(base, base->frag_block); + + free(base->blk_current); + + while (base->free_list != NULL) { + it = base->free_list; + base->free_list = it->next; + free(it); + } +} + int block_processor_init(sqfs_block_processor_t *base, size_t max_block_size, sqfs_compressor_t *cmp, sqfs_block_writer_t *wr, sqfs_frag_table_t *tbl) diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h index 496d415..d50a452 100644 --- a/lib/sqfs/block_processor/internal.h +++ b/lib/sqfs/block_processor/internal.h @@ -91,6 +91,8 @@ struct sqfs_block_processor_t { int (*sync)(sqfs_block_processor_t *proc); }; +SQFS_INTERNAL void block_processor_cleanup(sqfs_block_processor_t *base); + SQFS_INTERNAL int block_processor_init(sqfs_block_processor_t *base, size_t max_block_size, sqfs_compressor_t *cmp, diff --git a/lib/sqfs/block_processor/serial.c b/lib/sqfs/block_processor/serial.c index 7b3825d..f56f3cb 100644 --- a/lib/sqfs/block_processor/serial.c +++ b/lib/sqfs/block_processor/serial.c @@ -28,14 +28,7 @@ static void block_processor_destroy(sqfs_object_t *obj) { sqfs_block_processor_t *proc = (sqfs_block_processor_t *)obj; - free_block_list(proc->free_list); - - if (proc->frag_block != NULL) { - free_block_list(proc->frag_block->frag_list); - free(proc->frag_block); - } - - free(proc->blk_current); + block_processor_cleanup(proc); free(proc); } diff --git a/lib/sqfs/block_processor/winpthread.c b/lib/sqfs/block_processor/winpthread.c index 1519257..3531a3b 100644 --- a/lib/sqfs/block_processor/winpthread.c +++ b/lib/sqfs/block_processor/winpthread.c @@ -219,9 +219,7 @@ static void block_processor_destroy(sqfs_object_t *obj) free_blk_list(proc->proc_queue); free_blk_list(proc->io_queue); free_blk_list(proc->done); - free_blk_list(proc->base.free_list); - free(proc->base.blk_current); - free(proc->base.frag_block); + block_processor_cleanup(&proc->base); free(proc); } -- cgit v1.2.3