You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
~DAGNode() erases from 'parents' while iterating over it (container-overflow under ASan) #86
DAGNode::~DAGNode() iterates parents with a range-based for while remove_parent(*parent) erases elements from that very vector. That is iterator invalidation (undefined behaviour). With libstdc++ container annotations ASan reports it on the most trivial graph.
Reproducer
// does destroying a feature graph read past size() of a std::vector? (run with -fsanitize=address -D_GLIBCXX_SANITIZE_VECTOR)
#include<grunk/dynamic.hpp>
#include<cstdio>intmain() {
grunk::state g;
g.register_function("add", [](double a, double b) { return a + b; });
{
auto x = g.feature(1.0).with_id("x");
auto y = g.feature(2.0).with_id("y");
auto z = g.action("add", x, y);
auto w = g.action("add", z, x);
std::printf("%g\n", w.value().as<double>());
}
std::printf("done\n");
}
ERROR: AddressSanitizer: container-overflow on address ...
READ of size 8 at ... thread T0
#0 std::__shared_ptr<parametric::DAGNode, ...>::operator bool() const
#1 parametric::DAGNode::~DAGNode() parametric/dag.hpp:322
#2 parametric::ClonableDAGNode<grunk::ActionDynamic>::~ClonableDAGNode() dag.hpp:371
#3 parametric::ComputeNode<grunk::ActionDynamic, ...>::~ComputeNode()
#4 grunk::ActionDynamic::~ActionDynamic()
Cause
virtual~DAGNode() {
for (constauto& parent : parents) { // iterating `parents` ...if (parent) remove_parent(*parent); // ... while remove_parent() does parents.erase(...) on the same vector
}
}
Suggestion
Detach first: auto old = std::move(parents); parents.clear(); for (auto& p : old) if (p) remove_child_entry(*p); (or loop while (!parents.empty())). Note that it also never succeeds in removing the child entry from the parent (see the other issue about dead childs entries).
Environment: grunk main (8af34a7, 0.5.0), parametric 0.3.5, sol2 3.5.0, Lua 5.4.8, GCC 15.3 (conda-forge), Linux x86-64; WebAssembly: Emscripten 3.1.58.
(Found while building a prototype GUI/viewer on top of grunk.)
Activity
fix #86
Merge pull request #87 from grunk-dev/86-dagnode-erases-from-parents-…