Skip to content

Commit

Permalink
composefs-info: Fix memory handling for calloc
Browse files Browse the repository at this point in the history
* Free memory when done.
* Add NULL check for calloc result.

Signed-off-by: Alexander Larsson <[email protected]>
  • Loading branch information
alexlarsson committed Sep 15, 2023
1 parent ca46d09 commit 97a2f86
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tools/composefs-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ static void print_objects(struct lcfs_node_s *node)
get_objects(node, ht);

size_t n_objects = hash_get_n_entries(ht);
char **objects = calloc(n_objects, sizeof(char *));
cleanup_free char **objects = calloc(n_objects, sizeof(char *));
if (objects == NULL)
errx(EXIT_FAILURE, "Out of memory");

hash_get_entries(ht, (void **)objects, n_objects);

Expand Down

0 comments on commit 97a2f86

Please sign in to comment.