Skip to content

[DF] Possible use after delete of the functor passed to PassAsVec #8276

@eguiraud

Description

@eguiraud

To Reproduce

The following code:

#include <iostream>
#include <utility>
#include <vector>
#include <ROOT/RDFHelpers.hxx>

auto foo() {
  double f = 42.;

  auto fn = [f](std::vector<int>) { std::cout << f << std::endl; };
  fn({});
  auto f2 = ROOT::RDF::PassAsVec<1, int>(fn);
  f2(3);
  return f2;
}

int main() {
  auto fn = foo();
  fn(1);
  return 0;
}

prints

42
42
4.66901e-310

instead of

42
42
42

The problem is that the PassAsVecHelper type stores a reference to the the lambda function.
Valgrind does not see the problem (lambdas are stack-allocated), -fsanitize=address does.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions