From 97a2f869e3c7169a33d682bfae5f2d1f1b2f7110 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 15 Sep 2023 09:56:50 +0200 Subject: [PATCH] composefs-info: Fix memory handling for calloc * Free memory when done. * Add NULL check for calloc result. Signed-off-by: Alexander Larsson --- tools/composefs-info.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/composefs-info.c b/tools/composefs-info.c index 89622a37..339bfb41 100644 --- a/tools/composefs-info.c +++ b/tools/composefs-info.c @@ -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);