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 --- tests/libsqfs/table.c | 6 +++--- tests/libsqfs/xattr_benchmark.c | 4 ++-- tests/libsqfs/xattr_writer.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/libsqfs') diff --git a/tests/libsqfs/table.c b/tests/libsqfs/table.c index ed373a7..3e44fa3 100644 --- a/tests/libsqfs/table.c +++ b/tests/libsqfs/table.c @@ -84,7 +84,7 @@ static sqfs_s32 dummy_uncompress(sqfs_compressor_t *cmp, const sqfs_u8 *in, } static sqfs_file_t dummy_file = { - { NULL, NULL }, + { 1, NULL, NULL }, dummy_read_at, dummy_write_at, dummy_get_size, @@ -92,7 +92,7 @@ static sqfs_file_t dummy_file = { }; static sqfs_compressor_t dummy_compressor = { - { NULL, NULL }, + { 1, NULL, NULL }, NULL, NULL, NULL, @@ -100,7 +100,7 @@ static sqfs_compressor_t dummy_compressor = { }; static sqfs_compressor_t dummy_uncompressor = { - { NULL, NULL }, + { 1, NULL, NULL }, NULL, NULL, NULL, diff --git a/tests/libsqfs/xattr_benchmark.c b/tests/libsqfs/xattr_benchmark.c index 918a636..072dd06 100644 --- a/tests/libsqfs/xattr_benchmark.c +++ b/tests/libsqfs/xattr_benchmark.c @@ -113,10 +113,10 @@ int main(int argc, char **argv) } /* cleanup */ - sqfs_destroy(xwr); + sqfs_drop(xwr); return EXIT_SUCCESS; fail: - sqfs_destroy(xwr); + sqfs_drop(xwr); return EXIT_FAILURE; fail_arg: fputs("Try `xattr_benchmark --help' for more information.\n", stderr); diff --git a/tests/libsqfs/xattr_writer.c b/tests/libsqfs/xattr_writer.c index dfc8966..f7d0734 100644 --- a/tests/libsqfs/xattr_writer.c +++ b/tests/libsqfs/xattr_writer.c @@ -54,7 +54,7 @@ static sqfs_s32 dummy_compress(sqfs_compressor_t *cmp, const sqfs_u8 *in, } static sqfs_file_t dummy_file = { - { NULL, NULL }, + { 1, NULL, NULL }, NULL, dummy_write_at, dummy_get_size, @@ -62,7 +62,7 @@ static sqfs_file_t dummy_file = { }; static sqfs_compressor_t dummy_compressor = { - { NULL, NULL }, + { 1, NULL, NULL }, NULL, NULL, NULL, @@ -318,6 +318,6 @@ int main(int argc, char **argv) TEST_EQUAL_UI(offset, file_used); /* cleanup */ - sqfs_destroy(xwr); + sqfs_drop(xwr); return EXIT_SUCCESS; } -- cgit v1.2.3