From 456d618aa79fb883908bc2d4f36e20c261028ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sj=C3=B6lund?= Date: Mon, 25 Mar 2024 07:39:32 +0100 Subject: [PATCH] erofs: Add missing free() and lcfs_node_unref() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Erik Sjölund --- libcomposefs/lcfs-writer-erofs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libcomposefs/lcfs-writer-erofs.c b/libcomposefs/lcfs-writer-erofs.c index 46817ec..e5e81aa 100644 --- a/libcomposefs/lcfs-writer-erofs.c +++ b/libcomposefs/lcfs-writer-erofs.c @@ -347,16 +347,17 @@ static int compute_erofs_shared_xattrs(struct lcfs_ctx_s *ctx) ent = hash_lookup(xattr_hash, &hkey); if (ent == NULL) { - struct hasher_xattr_s *new_ent = + cleanup_free struct hasher_xattr_s *new_ent = calloc(1, sizeof(struct hasher_xattr_s)); if (new_ent == NULL) { goto fail; } new_ent->xattr = &node->xattrs[i]; ent = hash_insert(xattr_hash, new_ent); - if (ent == NULL) { + if (ent == NULL) goto fail; - } + assert(ent == new_ent); /* Due to result from previously run hash_lookup() */ + new_ent = NULL; } ent->count++; } @@ -1598,7 +1599,7 @@ static struct lcfs_node_s *lcfs_build_node_from_image(struct lcfs_image_data *da bool tailpacked; size_t xattr_size; struct hasher_node_s ht_entry = { nid }; - struct hasher_node_s *new_ht_entry; + cleanup_free struct hasher_node_s *new_ht_entry = NULL; struct hasher_node_s *existing; uint64_t n_blocks; uint64_t last_oob_block; @@ -1630,9 +1631,11 @@ static struct lcfs_node_s *lcfs_build_node_from_image(struct lcfs_image_data *da new_ht_entry->nid = nid; new_ht_entry->node = node; if (hash_insert(data->node_hash, new_ht_entry) == NULL) { + lcfs_node_unref(node); errno = ENOMEM; return NULL; } + new_ht_entry = NULL; if (erofs_inode_is_compact(cino)) { const struct erofs_inode_compact *c = &cino->compact;