Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eguiraud opened this issue May 28, 2021 · 0 comments · Fixed by #8277
Closed

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

eguiraud opened this issue May 28, 2021 · 0 comments · Fixed by #8277

Comments

@eguiraud
Copy link
Member

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.

@eguiraud eguiraud self-assigned this May 28, 2021
eguiraud added a commit to eguiraud/root that referenced this issue May 28, 2021
eguiraud added a commit to eguiraud/root that referenced this issue May 28, 2021
Make sure to always store the callables by value.
This fixes root-project#8276.
eguiraud added a commit that referenced this issue May 29, 2021
eguiraud added a commit that referenced this issue May 29, 2021
Make sure to always store the callables by value.
This fixes #8276.
@eguiraud eguiraud added this to Issues in Fixed in 6.26/00 via automation May 29, 2021
eguiraud added a commit to eguiraud/root that referenced this issue May 29, 2021
Make sure to always store the callables by value.
This fixes root-project#8276.
eguiraud added a commit that referenced this issue May 30, 2021
Make sure to always store the callables by value.
This fixes #8276.
@eguiraud eguiraud added this to Issues in Fixed in 6.24/02 via automation May 30, 2021
pzhristov pushed a commit to alisw/root that referenced this issue Aug 27, 2021
pzhristov pushed a commit to alisw/root that referenced this issue Aug 27, 2021
Make sure to always store the callables by value.
This fixes root-project#8276.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant