Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/shammodels/gsph/include/shammodels/gsph/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ namespace shammodels::gsph {

// Serial patch tree control
void gen_serial_patch_tree();
inline void reset_serial_patch_tree() { storage.serial_patch_tree.reset(); }
inline void reset_serial_patch_tree() {
shambase::get_check_ref(storage.serial_patch_tree_ref).free_alloc();
storage.serial_patch_tree.reset();
}
Comment on lines +92 to +95

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The use of free_alloc() on serial_patch_tree_ref is concerning. SerialPatchTreeRefEdge holds a non-owning raw pointer (patch_tree) to an object managed by storage.serial_patch_tree. The name free_alloc strongly implies deallocation. If this method attempts to delete the raw pointer, it will lead to a double-free when storage.serial_patch_tree is reset, which is a critical memory corruption bug.

If the intention of free_alloc() is simply to nullify the internal pointer (e.g., patch_tree = nullptr;), the method is dangerously misnamed and should be renamed to something like clear_reference() or reset() to avoid confusion and prevent future misuse.

Given the potential for a critical bug, please verify the implementation of SerialPatchTreeRefEdge::free_alloc() and consider renaming it for clarity and safety.


// Ghost handling - use GSPH ghost handler with Newtonian field names
using GhostHandle = GSPHGhostHandler<Tvec>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "shamrock/solvergraph/FieldRefs.hpp"
#include "shamrock/solvergraph/Indexes.hpp"
#include "shamrock/solvergraph/ScalarsEdge.hpp"
#include "shamrock/solvergraph/SerialPatchTreeEdge.hpp"
#include "shamrock/solvergraph/SolverGraph.hpp"
#include "shamsys/legacy/log.hpp"
#include "shamtree/CompressedLeafBVH.hpp"
#include "shamtree/KarrasRadixTreeField.hpp"
Expand Down Expand Up @@ -70,6 +72,8 @@ namespace shammodels::gsph {

using RTree = shamtree::CompressedLeafBVH<Tmorton, Tvec, 3>;

shamrock::solvergraph::SolverGraph solver_graph;

/// Particle counts per patch
std::shared_ptr<shamrock::solvergraph::Indexes<u32>> part_counts;
std::shared_ptr<shamrock::solvergraph::Indexes<u32>> part_counts_with_ghost;
Expand All @@ -84,6 +88,8 @@ namespace shammodels::gsph {
/// Patch rank ownership
std::shared_ptr<shamrock::solvergraph::ScalarsEdge<u32>> patch_rank_owner;

std::shared_ptr<shamrock::solvergraph::SerialPatchTreeRefEdge<Tvec>> serial_patch_tree_ref;

/// Serial patch tree for load balancing
Component<SerialPatchTree<Tvec>> serial_patch_tree;

Expand Down
10 changes: 10 additions & 0 deletions src/shammodels/gsph/src/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ void shammodels::gsph::Solver<Tvec, Kern>::init_solver_graph() {
storage.neigh_cache
= std::make_shared<shammodels::sph::solvergraph::NeighCache>(edges::neigh_cache, "neigh");

// Register serial patch tree reference edge for dependency tracking
storage.serial_patch_tree_ref = storage.solver_graph.register_edge(
"serial_patch_tree",
shamrock::solvergraph::SerialPatchTreeRefEdge<Tvec>(
"serial_patch_tree", "\\mathcal{T}_{\\rm patch}"));

storage.omega = std::make_shared<shamrock::solvergraph::Field<Tscal>>(1, "omega", "\\Omega");
storage.density = std::make_shared<shamrock::solvergraph::Field<Tscal>>(1, "density", "\\rho");
storage.pressure = std::make_shared<shamrock::solvergraph::Field<Tscal>>(1, "pressure", "P");
Expand Down Expand Up @@ -121,6 +127,10 @@ void shammodels::gsph::Solver<Tvec, Kern>::gen_serial_patch_tree() {
SerialPatchTree<Tvec> _sptree = SerialPatchTree<Tvec>::build(scheduler());
_sptree.attach_buf();
storage.serial_patch_tree.set(std::move(_sptree));

// Set solvergraph edge reference to the stored tree
shambase::get_check_ref(storage.serial_patch_tree_ref).patch_tree
= storage.serial_patch_tree.get();
}

template<class Tvec, template<class> class Kern>
Expand Down