Fix bug in add_subtree_to_route_tree that can result in double free.
Previous code potentially added a rt_node to two linked_rt_edge's,
resulting in a double free when freeing the tree.
Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
diff --git a/vpr/src/route/route_tree_timing.cpp b/vpr/src/route/route_tree_timing.cpp
index 845394e..cff2126 100644
--- a/vpr/src/route/route_tree_timing.cpp
+++ b/vpr/src/route/route_tree_timing.cpp
@@ -287,6 +287,7 @@
downstream_rt_node = sink_rt_node;
std::unordered_set<int> main_branch_visited;
+ std::unordered_set<int> all_visited;
inode = hptr->u.prev.node;
t_edge_size iedge = hptr->u.prev.edge;
short iswitch = device_ctx.rr_nodes[inode].edge_switch(iedge);
@@ -297,9 +298,15 @@
while (rr_node_to_rt_node[inode] == nullptr) { //Not connected to existing routing
main_branch_visited.insert(inode);
+ all_visited.insert(inode);
linked_rt_edge = alloc_linked_rt_edge();
linked_rt_edge->child = downstream_rt_node;
+
+ // Also mark downstream_rt_node->inode as visited to prevent
+ // add_non_configurable_to_route_tree from potentially adding
+ // downstream_rt_node to the rt tree twice.
+ all_visited.insert(downstream_rt_node->inode);
linked_rt_edge->iswitch = iswitch;
linked_rt_edge->next = nullptr;
@@ -340,7 +347,6 @@
//Expand (recursively) each of the main-branch nodes adding any
//non-configurably connected nodes
- std::unordered_set<int> all_visited = main_branch_visited;
for (int rr_node : main_branch_visited) {
add_non_configurable_to_route_tree(rr_node, false, all_visited);
}
@@ -499,11 +505,11 @@
/* Having set the value of C_downstream_addition, we must check whethere the parent switch
* is a buffered or unbuffered switch with the if statement below. If the parent switch is
- * a buffered switch, then the parent node's downsteam capacitance is increased by the
+ * a buffered switch, then the parent node's downsteam capacitance is increased by the
* value of the parent switch's internal capacitance in the if statement below.
- * Correspondingly, the ancestors' downstream capacitance will be updated by the same
+ * Correspondingly, the ancestors' downstream capacitance will be updated by the same
* value through the while loop. Otherwise, if the parent switch is unbuffered, then
- * the if statement will be ignored, and the parent and ancestral nodes' downstream
+ * the if statement will be ignored, and the parent and ancestral nodes' downstream
* capacitance will be increased by the sum of the child's downstream capacitance with
* the internal capacitance of the parent switch in the while loop/.*/