From bd0513218575b7b22106d4beb63c27320746e56d Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Wed, 11 Dec 2024 17:45:51 +0100 Subject: [PATCH] bsys: Free dependency tree at the end Not really necessary, but we might as well since it's just a single simple function call. --- src/bsys.c | 3 ++- src/deps.c | 18 +++++++++--------- src/deps.h | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/bsys.c b/src/bsys.c index 123a1246..d7319d8d 100644 --- a/src/bsys.c +++ b/src/bsys.c @@ -60,8 +60,9 @@ int bsys_dep_tree(bsys_t const* bsys, int argc, char* argv[]) { // Serialize and output it. char* const STR_CLEANUP serialized = dep_node_serialize(tree); - printf(DEP_TAG_START "%s" DEP_TAG_END, serialized); + + deps_tree_free(tree); return 0; } diff --git a/src/deps.c b/src/deps.c index f4a30668..dd0cb089 100644 --- a/src/deps.c +++ b/src/deps.c @@ -250,7 +250,7 @@ static void free_node(dep_node_t* node) { free(node->children); } -static void free_tree(dep_node_t* tree) { +void deps_tree_free(dep_node_t* tree) { free_node(tree); free(tree); } @@ -281,7 +281,7 @@ dep_node_t* deps_tree(flamingo_val_t* deps_vec, size_t path_len, uint64_t* path_ if (gen_local_path(".", NULL, &human, &tree->path) < 0) { LOG_FATAL("Could not get would-be dependency name of current project." PLZ_REPORT); - free_tree(tree); + deps_tree_free(tree); return NULL; } @@ -294,7 +294,7 @@ dep_node_t* deps_tree(flamingo_val_t* deps_vec, size_t path_len, uint64_t* path_ LOG_WARN("Dependency tree is circular after adding '%s'.", human); *circular = true; - free_tree(tree); + deps_tree_free(tree); return NULL; } } @@ -346,7 +346,7 @@ dep_node_t* deps_tree(flamingo_val_t* deps_vec, size_t path_len, uint64_t* path_ fclose(tree_f); if (dep_node_deserialize(tree, serialized) < 0) { - free_tree(tree); + deps_tree_free(tree); return NULL; } @@ -398,7 +398,7 @@ build_tree:; LOG_FATAL("Failed to get dependency tree of '%s'%s", dep->human, out ? ":" : "."); printf("%s", out); - free_tree(tree); + deps_tree_free(tree); return NULL; } @@ -406,7 +406,7 @@ build_tree:; LOG_WARN("Dependency tree is circular after adding '%s'.", dep->human); *circular = true; - free_tree(tree); + deps_tree_free(tree); return NULL; } @@ -415,7 +415,7 @@ build_tree:; if (dep_node_deserialize(&node, out) < 0) { LOG_FATAL("Failed to deserialize dependency tree of '%s'.", dep->human); - free_tree(tree); + deps_tree_free(tree); return NULL; } @@ -434,7 +434,7 @@ build_tree:; if (f == NULL) { LOG_FATAL("Could not open dependency hash file '%s' for writing: %s", hash_path, strerror(errno)); - free_tree(tree); + deps_tree_free(tree); return NULL; } @@ -448,7 +448,7 @@ build_tree:; if (f == NULL) { LOG_FATAL("Could not open dependency tree file '%s' for writing: %s", tree_path, strerror(errno)); - free_tree(tree); + deps_tree_free(tree); return NULL; } diff --git a/src/deps.h b/src/deps.h index eb85eb9c..97825acf 100644 --- a/src/deps.h +++ b/src/deps.h @@ -23,6 +23,7 @@ struct dep_node_t { }; dep_node_t* deps_tree(flamingo_val_t* deps_vec, size_t path_len, uint64_t* path_hashes, bool* circular); +void deps_tree_free(dep_node_t* tree); // Dependency serialization.