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
ParameterAcceptor::clear() leads to use after free #15111
Comments
Maybe a better design is to use |
Is there a good reason for having |
@masterleinad I currently have a use case: I want to get all parameters associated to one class (and all dependent objects), after that clear the global |
@bangerth At first glance I believe this should be doable (meaning to use signals for all of these operations). We will have to ensure that slots are called sequentially, though (because our |
I'm working on a fix. |
The following, admittedly, not very practical piece of code triggers a use after free:
The triggered assertion reads:
The offending line of code in
source/base/parameter_acceptor.cc
is:The underlying problem is the fact that a call to
clear()
resets the class_list, which is astd::vector
ofSmartPointer<ParameterAcceptor>
objects that gets reset.But every instance of a
ParameterAcceptor
object stores an indexacceptor_id
to it's pointer's position in the vector.Naturally, after the ParameterAcceptor class has been cleared this position is no longer valid, hence the assert.
I think, this approach is fundamentally broken.
The
class_list
object should probably be astd::set<dealii::ParameterAcceptor*>
and not astd::vector
of a SmartPointer.A SmartPointer is of very little utility anyway: The desctructor of
dealii::ParameterAcceptor
will already remove the instance from thestd::vector
/std::set
, which basically guarantees that a use-after-free thatSmartPointer
guards against cannot happen. (*)So I think the way to go is to remove the
acceptor_id
and simply store the address ot the object in astd::set
.(*) None of this is thread-safe, which is a story in itself.
The text was updated successfully, but these errors were encountered: