Skip to content

Commit

Permalink
node.c: Tighten node clean up logic.
Browse files Browse the repository at this point in the history
* Teardown I/O transformers and session only after we've checked if
  the node was already shutdown, to avoid duplicate cleanup attempt.
* Only call node_shutdown on the active shutdown attempt,
  to avoid the duplicate call to node_shutdown in the first place.
  • Loading branch information
InterLinked1 committed Jan 25, 2025
1 parent 8ac2399 commit 02435a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bbs/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int bbs_io_session_unregister(struct bbs_io_transformations *s)
RWLIST_UNLOCK(&sessions);
if (!i) {
/* We traversed the entire list, so this count is accurate */
bbs_warning("Transformation %p does not have an active session (%d total)\n", s, total);
bbs_warning("Transformation %p does not have an active session (%d total active)\n", s, total);
}
return i ? 0 : -1;
}
Expand Down
9 changes: 5 additions & 4 deletions bbs/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,6 @@ static void node_shutdown(struct bbs_node *node, int unique)
time_t now;
int wasloggedin = 0;

bbs_io_teardown_all_transformers(&node->trans);
bbs_io_session_unregister(&node->trans);

/* Prevent node from being freed until we release the lock. */
bbs_node_lock(node);
if (!node->active) {
Expand All @@ -602,6 +599,9 @@ static void node_shutdown(struct bbs_node *node, int unique)

now = time(NULL);

bbs_io_teardown_all_transformers(&node->trans);
bbs_io_session_unregister(&node->trans);

bbs_node_kill_child(node);

/* Destroy the user */
Expand Down Expand Up @@ -711,9 +711,10 @@ int bbs_node_unlink(struct bbs_node *node)
/* If bbs_node_shutdown_all was used, nodes are removed from the list
* but not freed there. */
bbs_debug(1, "Node %d was already unlinked, freeing directly\n", node->id);
} else {
node_shutdown(node, 1);
}

node_shutdown(node, 1);
/* If unlinking a single node, also free here */
node_free(node);
return 0;
Expand Down

0 comments on commit 02435a1

Please sign in to comment.