diff --git a/rviz_common/src/rviz_common/properties/property.cpp b/rviz_common/src/rviz_common/properties/property.cpp index 444ed4531..c325ffeab 100644 --- a/rviz_common/src/rviz_common/properties/property.cpp +++ b/rviz_common/src/rviz_common/properties/property.cpp @@ -37,6 +37,7 @@ #include // NOLINT: cpplint is unable to handle the include order here #include // NOLINT: cpplint is unable to handle the include order here #include // NOLINT: cpplint is unable to handle the include order here +#include // NOLINT: cpplint is unable to handle the include order here #include // NOLINT: cpplint is unable to handle the include order here #include // NOLINT: cpplint is unable to handle the include order here #include // NOLINT: cpplint is unable to handle the include order here @@ -386,10 +387,12 @@ void Property::setModel(PropertyTreeModel * model) { model_ = model; if (model_ && hidden_) { - // process propertyHiddenChanged after insertion into model has finishedAdd commentMore actions - QTimer::singleShot(0, model_, [this]() { - if (model_) { - model_->emitPropertyHiddenChanged(this); + // process propertyHiddenChanged after insertion into model has finished + // Use QPointer to track Property lifetime and avoid use-after-free + QPointer self = this; + QTimer::singleShot(0, model_, [self]() { + if (self && self->model_) { + self->model_->emitPropertyHiddenChanged(self); } }); }