Skip to content

Commit

Permalink
bsys: Free dependency tree at the end
Browse files Browse the repository at this point in the history
Not really necessary, but we might as well since it's just a single simple function call.
  • Loading branch information
obiwac committed Dec 11, 2024
1 parent 3e65473 commit bd05132
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/bsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
18 changes: 9 additions & 9 deletions src/deps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -398,15 +398,15 @@ 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;
}

if (strstr(out, BOB_DEPS_CIRCULAR) != NULL) {
LOG_WARN("Dependency tree is circular after adding '%s'.", dep->human);
*circular = true;

free_tree(tree);
deps_tree_free(tree);
return NULL;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/deps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit bd05132

Please sign in to comment.