From 47f24f2a8faf71395a1d054e9823beb000442cce Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 4 Dec 2022 01:33:45 +0100 Subject: 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 --- bin/gensquashfs/filemap_xattr.c | 4 ++-- bin/gensquashfs/fstree_from_file.c | 2 +- bin/gensquashfs/mkfs.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'bin/gensquashfs') diff --git a/bin/gensquashfs/filemap_xattr.c b/bin/gensquashfs/filemap_xattr.c index 9693a54..dd76b50 100644 --- a/bin/gensquashfs/filemap_xattr.c +++ b/bin/gensquashfs/filemap_xattr.c @@ -193,12 +193,12 @@ xattr_open_map_file(const char *path) { goto fail; } - sqfs_destroy(file); + sqfs_drop(file); return map; fail: xattr_close_map_file(map); fail_close: - sqfs_destroy(file); + sqfs_drop(file); return NULL; } diff --git a/bin/gensquashfs/fstree_from_file.c b/bin/gensquashfs/fstree_from_file.c index feacbbc..e26d4b1 100644 --- a/bin/gensquashfs/fstree_from_file.c +++ b/bin/gensquashfs/fstree_from_file.c @@ -586,6 +586,6 @@ int fstree_from_file(fstree_t *fs, const char *filename, const char *basepath) ret = fstree_from_file_stream(fs, fp, basepath); - sqfs_destroy(fp); + sqfs_drop(fp); return ret; } diff --git a/bin/gensquashfs/mkfs.c b/bin/gensquashfs/mkfs.c index 171a887..c773dd7 100644 --- a/bin/gensquashfs/mkfs.c +++ b/bin/gensquashfs/mkfs.c @@ -59,7 +59,7 @@ static int pack_files(sqfs_block_processor_t *data, fstree_t *fs, flags |= SQFS_BLK_DONT_FRAGMENT; ret = write_data_from_file(path, data, &fi->inode, file, flags); - sqfs_destroy(file); + sqfs_drop(file); free(node_path); if (ret) @@ -209,7 +209,7 @@ out: if (sehnd != NULL) selinux_close_context_file(sehnd); if (sortfile != NULL) - sqfs_destroy(sortfile); + sqfs_drop(sortfile); free(opt.packdir); return status; } -- cgit v1.2.3