Fix component ownership.

When switching from raw pointers toward shared_ptr, the destructor
wasn't updated correctly.

This patch:
- Fixes the issue.
- Add two regression tests.
- Use address sanitizer for the tests.

This fixes: https://github.com/ArthurSonzogni/FTXUI/issues/115
This commit is contained in:
ArthurSonzogni
2021-06-21 22:49:42 +02:00
committed by Arthur Sonzogni
parent 478d7e8bca
commit 91c5954fe2
3 changed files with 42 additions and 1 deletions

View File

@@ -19,7 +19,8 @@ class CaptureMouseImpl : public CapturedMouseInterface {
} // namespace
ComponentBase::~ComponentBase() {
Detach();
while (children_.size() != 0)
children_.back()->Detach();
}
/// @brief Return the parent ComponentBase, or nul if any.
@@ -142,6 +143,7 @@ void ComponentBase::Detach() {
return this == that.get();
});
parent_->children_.erase(it);
parent_ = nullptr;
}
} // namespace ftxui