Skip to content

Commit

Permalink
Merge pull request #262 from eriksjolund/add-error-check-and-rearrange
Browse files Browse the repository at this point in the history
handle NULL from lcfs_node_new() and move errno code into the function
  • Loading branch information
cgwalters authored Mar 20, 2024
2 parents 2cb505b + 396a3b8 commit 9b85011
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 0 additions & 4 deletions libcomposefs/lcfs-writer-erofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,6 @@ static int add_overlay_whiteouts(struct lcfs_node_s *root)

child = lcfs_node_new();
if (child == NULL) {
errno = ENOMEM;
return -1;
}

Expand Down Expand Up @@ -1238,7 +1237,6 @@ static int rewrite_tree_node_for_erofs(struct lcfs_ctx_s *ctx,
if (existing == NULL) {
struct lcfs_node_s *link = lcfs_node_new();
if (link == NULL) {
errno = ENOMEM;
return -1;
}
lcfs_node_make_hardlink(link, node);
Expand All @@ -1253,7 +1251,6 @@ static int rewrite_tree_node_for_erofs(struct lcfs_ctx_s *ctx,
if (existing == NULL) {
struct lcfs_node_s *link = lcfs_node_new();
if (link == NULL) {
errno = ENOMEM;
return -1;
}
lcfs_node_make_hardlink(link, parent);
Expand Down Expand Up @@ -1612,7 +1609,6 @@ static struct lcfs_node_s *lcfs_build_node_from_image(struct lcfs_image_data *da

node = lcfs_node_new();
if (node == NULL) {
errno = ENOMEM;
return NULL;
}

Expand Down
4 changes: 3 additions & 1 deletion libcomposefs/lcfs-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,10 @@ static int read_xattrs(struct lcfs_node_s *ret, int dirfd, const char *fname,
struct lcfs_node_s *lcfs_node_new(void)
{
struct lcfs_node_s *node = calloc(1, sizeof(struct lcfs_node_s));
if (node == NULL)
if (node == NULL) {
errno = ENOMEM;
return NULL;
}

node->ref_count = 1;
node->inode.st_nlink = 1;
Expand Down
3 changes: 3 additions & 0 deletions tools/mkcomposefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ static char *tree_from_dump_line(dump_info *info, const char *line, size_t line_
return err;

cleanup_node struct lcfs_node_s *node = lcfs_node_new();
if (node == NULL) {
oom();
}
lcfs_node_set_mode(node, mode);

err = tree_add_node(info, path, node);
Expand Down

0 comments on commit 9b85011

Please sign in to comment.