diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-12-04 01:33:45 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-01-19 16:24:56 +0100 |
commit | 47f24f2a8faf71395a1d054e9823beb000442cce (patch) | |
tree | dd01d8b69125b3dda444c9b92437ad0c5a0af9bc /lib/common/writer | |
parent | 4160b50a0b4c51f8b7191928cdf38d9fb0147fe2 (diff) |
Implement rudimentary reference counting for sqfs_object_t
Implement grab/drop functions to increase/decrease reference count
and destroy the object if the count drops to 0.
Make sure that all objects that maintain internal references actually
grab that reference, duplicate it in the copy function, drop it in
the destroy handler.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common/writer')
-rw-r--r-- | lib/common/writer/cleanup.c | 24 | ||||
-rw-r--r-- | lib/common/writer/init.c | 25 |
2 files changed, 23 insertions, 26 deletions
diff --git a/lib/common/writer/cleanup.c b/lib/common/writer/cleanup.c index 1af7a99..a3fd039 100644 --- a/lib/common/writer/cleanup.c +++ b/lib/common/writer/cleanup.c @@ -10,20 +10,18 @@ void sqfs_writer_cleanup(sqfs_writer_t *sqfs, int status) { - if (sqfs->xwr != NULL) - sqfs_destroy(sqfs->xwr); - - sqfs_destroy(sqfs->dirwr); - sqfs_destroy(sqfs->dm); - sqfs_destroy(sqfs->im); - sqfs_destroy(sqfs->idtbl); - sqfs_destroy(sqfs->data); - sqfs_destroy(sqfs->blkwr); - sqfs_destroy(sqfs->fragtbl); - sqfs_destroy(sqfs->cmp); - sqfs_destroy(sqfs->uncmp); + sqfs_drop(sqfs->xwr); + sqfs_drop(sqfs->dirwr); + sqfs_drop(sqfs->dm); + sqfs_drop(sqfs->im); + sqfs_drop(sqfs->idtbl); + sqfs_drop(sqfs->data); + sqfs_drop(sqfs->blkwr); + sqfs_drop(sqfs->fragtbl); + sqfs_drop(sqfs->cmp); + sqfs_drop(sqfs->uncmp); fstree_cleanup(&sqfs->fs); - sqfs_destroy(sqfs->outfile); + sqfs_drop(sqfs->outfile); if (status != EXIT_SUCCESS) { #if defined(_WIN32) || defined(__WINDOWS__) diff --git a/lib/common/writer/init.c b/lib/common/writer/init.c index 7940c3f..497fc6e 100644 --- a/lib/common/writer/init.c +++ b/lib/common/writer/init.c @@ -70,7 +70,7 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg) #ifdef WITH_LZO if (cfg.id == SQFS_COMP_LZO) { if (sqfs->cmp != NULL) - sqfs_destroy(sqfs->cmp); + sqfs_drop(sqfs->cmp); ret = lzo_compressor_create(&cfg, &sqfs->cmp); } @@ -87,7 +87,7 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg) #ifdef WITH_LZO if (cfg.id == SQFS_COMP_LZO) { if (ret == 0 && sqfs->uncmp != NULL) - sqfs_destroy(sqfs->uncmp); + sqfs_drop(sqfs->uncmp); ret = lzo_compressor_create(&cfg, &sqfs->uncmp); } @@ -193,27 +193,26 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg) return 0; fail_dm: - sqfs_destroy(sqfs->dm); + sqfs_drop(sqfs->dm); fail_im: - sqfs_destroy(sqfs->im); + sqfs_drop(sqfs->im); fail_xwr: - if (sqfs->xwr != NULL) - sqfs_destroy(sqfs->xwr); + sqfs_drop(sqfs->xwr); fail_id: - sqfs_destroy(sqfs->idtbl); + sqfs_drop(sqfs->idtbl); fail_data: - sqfs_destroy(sqfs->data); + sqfs_drop(sqfs->data); fail_fragtbl: - sqfs_destroy(sqfs->fragtbl); + sqfs_drop(sqfs->fragtbl); fail_blkwr: - sqfs_destroy(sqfs->blkwr); + sqfs_drop(sqfs->blkwr); fail_uncmp: - sqfs_destroy(sqfs->uncmp); + sqfs_drop(sqfs->uncmp); fail_cmp: - sqfs_destroy(sqfs->cmp); + sqfs_drop(sqfs->cmp); fail_fs: fstree_cleanup(&sqfs->fs); fail_file: - sqfs_destroy(sqfs->outfile); + sqfs_drop(sqfs->outfile); return -1; } |