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 /bin | |
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 'bin')
-rw-r--r-- | bin/gensquashfs/filemap_xattr.c | 4 | ||||
-rw-r--r-- | bin/gensquashfs/fstree_from_file.c | 2 | ||||
-rw-r--r-- | bin/gensquashfs/mkfs.c | 4 | ||||
-rw-r--r-- | bin/rdsquashfs/fill_files.c | 2 | ||||
-rw-r--r-- | bin/rdsquashfs/rdsquashfs.c | 16 | ||||
-rw-r--r-- | bin/sqfs2tar/sqfs2tar.c | 21 | ||||
-rw-r--r-- | bin/sqfsdiff/extract.c | 4 | ||||
-rw-r--r-- | bin/sqfsdiff/sqfsdiff.c | 20 | ||||
-rw-r--r-- | bin/tar2sqfs/process_tarball.c | 2 | ||||
-rw-r--r-- | bin/tar2sqfs/tar2sqfs.c | 9 |
10 files changed, 46 insertions, 38 deletions
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; } diff --git a/bin/rdsquashfs/fill_files.c b/bin/rdsquashfs/fill_files.c index 923bc12..3104146 100644 --- a/bin/rdsquashfs/fill_files.c +++ b/bin/rdsquashfs/fill_files.c @@ -158,7 +158,7 @@ static int fill_files(sqfs_data_reader_t *data, int flags) if (ret == 0) ret = ostream_flush(fp); - sqfs_destroy(fp); + sqfs_drop(fp); if (ret) return -1; } diff --git a/bin/rdsquashfs/rdsquashfs.c b/bin/rdsquashfs/rdsquashfs.c index 206b754..a18ac7f 100644 --- a/bin/rdsquashfs/rdsquashfs.c +++ b/bin/rdsquashfs/rdsquashfs.c @@ -221,11 +221,11 @@ int main(int argc, char **argv) if (sqfs_data_reader_dump(opt.cmdpath, data, n->inode, fp, super.block_size)) { - sqfs_destroy(fp); + sqfs_drop(fp); goto out; } - sqfs_destroy(fp); + sqfs_drop(fp); break; } case OP_UNPACK: @@ -267,18 +267,18 @@ int main(int argc, char **argv) out: sqfs_dir_tree_destroy(n); out_data: - sqfs_destroy(data); + sqfs_drop(data); out_dr: - sqfs_destroy(dirrd); + sqfs_drop(dirrd); out_id: - sqfs_destroy(idtbl); + sqfs_drop(idtbl); out_xr: if (xattr != NULL) - sqfs_destroy(xattr); + sqfs_drop(xattr); out_cmp: - sqfs_destroy(cmp); + sqfs_drop(cmp); out_file: - sqfs_destroy(file); + sqfs_drop(file); out_cmd: free(opt.cmdpath); return status; diff --git a/bin/sqfs2tar/sqfs2tar.c b/bin/sqfs2tar/sqfs2tar.c index 00d1e27..9dfa41e 100644 --- a/bin/sqfs2tar/sqfs2tar.c +++ b/bin/sqfs2tar/sqfs2tar.c @@ -124,7 +124,11 @@ int main(int argc, char **argv) } if (compressor > 0) { - out_file = ostream_compressor_create(out_file, compressor); + ostream_t *strm = ostream_compressor_create(out_file, + compressor); + sqfs_drop(out_file); + out_file = strm; + if (out_file == NULL) goto out_dirs; } @@ -251,20 +255,19 @@ out: if (root != NULL) sqfs_dir_tree_destroy(root); out_xr: - if (xr != NULL) - sqfs_destroy(xr); + sqfs_drop(xr); out_dr: - sqfs_destroy(dr); + sqfs_drop(dr); out_data: - sqfs_destroy(data); + sqfs_drop(data); out_id: - sqfs_destroy(idtbl); + sqfs_drop(idtbl); out_cmp: - sqfs_destroy(cmp); + sqfs_drop(cmp); out_fd: - sqfs_destroy(file); + sqfs_drop(file); out_ostrm: - sqfs_destroy(out_file); + sqfs_drop(out_file); out_dirs: for (i = 0; i < num_subdirs; ++i) free(subdirs[i]); diff --git a/bin/sqfsdiff/extract.c b/bin/sqfsdiff/extract.c index 0c68918..f2072d4 100644 --- a/bin/sqfsdiff/extract.c +++ b/bin/sqfsdiff/extract.c @@ -29,12 +29,12 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, } if (sqfs_data_reader_dump(path, data, inode, fp, block_size)) { - sqfs_destroy(fp); + sqfs_drop(fp); return -1; } ostream_flush(fp); - sqfs_destroy(fp); + sqfs_drop(fp); return 0; } diff --git a/bin/sqfsdiff/sqfsdiff.c b/bin/sqfsdiff/sqfsdiff.c index 0673f8d..9d29332 100644 --- a/bin/sqfsdiff/sqfsdiff.c +++ b/bin/sqfsdiff/sqfsdiff.c @@ -97,28 +97,28 @@ static int open_sfqs(sqfs_state_t *state, const char *path) return 0; fail_data: - sqfs_destroy(state->data); + sqfs_drop(state->data); fail_tree: sqfs_dir_tree_destroy(state->root); fail_dr: - sqfs_destroy(state->dr); + sqfs_drop(state->dr); fail_id: - sqfs_destroy(state->idtbl); + sqfs_drop(state->idtbl); fail_cmp: - sqfs_destroy(state->cmp); + sqfs_drop(state->cmp); fail_file: - sqfs_destroy(state->file); + sqfs_drop(state->file); return -1; } static void close_sfqs(sqfs_state_t *state) { - sqfs_destroy(state->data); + sqfs_drop(state->data); sqfs_dir_tree_destroy(state->root); - sqfs_destroy(state->dr); - sqfs_destroy(state->idtbl); - sqfs_destroy(state->cmp); - sqfs_destroy(state->file); + sqfs_drop(state->dr); + sqfs_drop(state->idtbl); + sqfs_drop(state->cmp); + sqfs_drop(state->file); } int main(int argc, char **argv) diff --git a/bin/tar2sqfs/process_tarball.c b/bin/tar2sqfs/process_tarball.c index c0ae5a3..6aaa24b 100644 --- a/bin/tar2sqfs/process_tarball.c +++ b/bin/tar2sqfs/process_tarball.c @@ -72,7 +72,7 @@ static int write_file(istream_t *input_file, sqfs_writer_t *sqfs, } ostream_flush(out); - sqfs_destroy(out); + sqfs_drop(out); if (ret) return -1; diff --git a/bin/tar2sqfs/tar2sqfs.c b/bin/tar2sqfs/tar2sqfs.c index 4e9ade9..572eb10 100644 --- a/bin/tar2sqfs/tar2sqfs.c +++ b/bin/tar2sqfs/tar2sqfs.c @@ -50,6 +50,8 @@ int main(int argc, char **argv) goto out_if; if (ret > 0) { + istream_t *strm; + if (!io_compressor_exists(ret)) { fprintf(stderr, "%s: %s compression is not supported.\n", @@ -58,7 +60,10 @@ int main(int argc, char **argv) goto out_if; } - input_file = istream_compressor_create(input_file, ret); + strm = istream_compressor_create(input_file, ret); + sqfs_drop(input_file); + input_file = strm; + if (input_file == NULL) return EXIT_FAILURE; } @@ -80,6 +85,6 @@ int main(int argc, char **argv) out: sqfs_writer_cleanup(&sqfs, status); out_if: - sqfs_destroy(input_file); + sqfs_drop(input_file); return status; } |