Misc fixes in erofs-utils
cover Misc fixes in erofs-utils
Hi,
Below series contains few small misc fixes found after running through clang static checker.
Sandeep Dhavale (7):
erofs-utils: fsck: Fix potential memory leak in error path
erofs-utils: lib: Remove redundant line to get padding
erofs-utils: lib: Fix memory leak if __erofs_battach() fails
erofs-utils: lib: Check for error from z_erofs_pack_file_from_fd()
erofs-utils: lib: Fix the memory leak in error path
erofs-utils: lib: Remove redundant assignment
erofs-utils: lib: tar: Initialize the variable to avoid using garbage
value
fsck/main.c | 4 +++- lib/blobchunk.c | 1 - lib/cache.c | 4 +++- lib/compress.c | 2 ++ lib/decompress.c | 4 +++- lib/namei.c | 1 - lib/tar.c | 2 +- 7 files changed, 12 insertions(+), 6 deletions(-)
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 1/7 erofs-utils: fsck: Fix potential memory leak in error path
Free the memory allocated for 'entry' if strdup() fails.
--- fsck/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fsck/main.c +3 -1
@@ -585,8 +585,10 @@ static int erofsfsck_hardlink_insert(erofs_nid_t nid, const char *path) entry->nid = nid; entry->path =strdup (path); -if (!entry->path) +if (!entry->path) { +free (entry);return -ENOMEM ; + }list_add_tail (&entry->list, &erofsfsck_link_hashtable[nid %NR_HARDLINK_HASHTABLE ]);
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 2/7 erofs-utils: lib: Remove redundant line to get padding
In reply to Sandeep Dhavale via Linux-erofspadding is only used in the next if() block. Remove the redundant call.
--- lib/blobchunk.c | 1 - 1 file changed, 1 deletion(-)
lib/blobchunk.c +0 -1
@@ -91,7 +91,6 @@ static struct erofs_blobchunk *erofs_blob_getchunk(struct erofs_sb_info *sbi,erofs_dbg ("Writing chunk (%u bytes) to %u" , chunksize, chunk->blkaddr); ret =fwrite (buf, chunksize,1 , blobfile); - padding =erofs_blkoff (sbi, chunksize);if (ret ==1 ) { padding =erofs_blkoff (sbi, chunksize);if (padding) {
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 3/7 erofs-utils: lib: Fix memory leak if __erofs_battach() fails
In reply to Sandeep Dhavale via Linux-erofsNeed to free allocated buffer_head bh if __erofs_battach() fails.
--- lib/cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/cache.c +3 -1
@@ -282,8 +282,10 @@ struct erofs_buffer_head *erofs_balloc(int type, erofs_off_t size, ret =__erofs_battach (bb, bh, size, alignsize, required_ext + inline_ext, false); -if (ret <0 ) +if (ret <0 ) { +free (bh);return ERR_PTR (ret); + }return bh; }
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 4/7 erofs-utils: lib: Check for error from z_erofs_pack_file_from_fd()
In reply to Sandeep Dhavale via Linux-erofsIf z_erofs_pack_file_from_fd() fails, take the error path to free up the allocated resources.
--- lib/compress.c | 2 ++ 1 file changed, 2 insertions(+)
lib/compress.c +2 -0
@@ -927,6 +927,8 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)if (cfg.c_all_fragments && !erofs_is_packed_inode (inode) && !inode->fragment_size) { ret =z_erofs_pack_file_from_fd (inode, fd, ctx.tof_chksum); +if (ret) + goto err_free_idata; }else {while (ctx.remaining) { const u64 rx = min_t(u64, ctx.remaining,
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 5/7 erofs-utils: lib: Fix the memory leak in error path
In reply to Sandeep Dhavale via Linux-erofsIf call to inflateInit2() fails, release the memory allocated for buff before returning.
--- lib/decompress.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/decompress.c +3 -1
@@ -126,8 +126,10 @@ static int z_erofs_decompress_deflate(struct z_erofs_decompress_req *rq) strm.avail_in =0 ; strm.next_in =Z_NULL ; ret =inflateInit2 (&strm,-15 ); -if (ret !=Z_OK ) +if (ret !=Z_OK ) { +free (buff);return zerr (ret); + } strm.next_in = src + inputmargin; strm.avail_in = rq->inputsize - inputmargin;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 6/7 erofs-utils: lib: Remove redundant assignment
In reply to Sandeep Dhavale via Linux-erofsThe intended assignment is already part of the next for loop initialization.
--- lib/namei.c | 1 - 1 file changed, 1 deletion(-)
lib/namei.c +0 -1
@@ -262,7 +262,6 @@ static int link_path_walk(const char *name, struct nameidata *nd)if (ret)return ret; - name = p;/* Skip until no more slashes. */ for (name = p; *name =='/' ; ++name) ;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 7/7 erofs-utils: lib: tar: Initialize the variable to avoid using garbage value
In reply to Sandeep Dhavale via Linux-erofsThe value in variable 'e' is checked without initializing and can wrongly signify end of tar 2 empty blocks.
--- lib/tar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tar.c +1 -1
@@ -549,7 +549,7 @@ int tarerofs_parse_tar(struct erofs_inode *root, struct erofs_tarfile *tar)char path[PATH_MAX ];struct erofs_pax_header eh = tar->global;struct erofs_sb_info *sbi = root->sbi; -bool e, whout, opq; +bool whout, opq, e = false;struct stat st;erofs_off_t tar_offset, data_offset;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Quoted 3 lines · Sandeep Dhavale
Hi,
Below series contains few small misc fixes found after running through clang static checker.
All these patches look good to me, will apply.
Thanks,
Gao Xiang
Quoted 20 lines
Sandeep Dhavale (7):
erofs-utils: fsck: Fix potential memory leak in error path
erofs-utils: lib: Remove redundant line to get padding
erofs-utils: lib: Fix memory leak if__erofs_battach()fails
erofs-utils: lib: Check for error fromz_erofs_pack_file_from_fd()
erofs-utils: lib: Fix the memory leak in error path
erofs-utils: lib: Remove redundant assignment
erofs-utils: lib: tar: Initialize the variable to avoid using garbage
valuefsck/main.c | 4 +++- lib/blobchunk.c | 1 - lib/cache.c | 4 +++- lib/compress.c | 2 ++ lib/decompress.c | 4 +++- lib/namei.c | 1 - lib/tar.c | 2 +- 7 files changed, 12 insertions(+), 6 deletions(-)