Make data source objects "parentless"

The SeatInterface cleans up currentSelection and currentPrimarySelection
when the AbstractDataSource::aboutToBeDestroyed() signal is emitted, but
since the data source and primary data source have parent objects, they
can be potentially destroyed without emitting the aboutToBeDestroyed()
signal and thus leaving dangling pointers in SeatInterface.

CCBUG: 449101
This commit is contained in:
Vlad Zahorodnii 2022-01-25 09:59:59 +02:00
parent fd3a7c3c99
commit c793dd93d2
3 changed files with 4 additions and 6 deletions

View file

@ -94,8 +94,7 @@ void DataSourceInterfacePrivate::data_source_set_actions(Resource *resource, uin
} }
DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent, wl_resource *resource) DataSourceInterface::DataSourceInterface(DataDeviceManagerInterface *parent, wl_resource *resource)
: AbstractDataSource(parent) : d(new DataSourceInterfacePrivate(this, resource))
, d(new DataSourceInterfacePrivate(this, resource))
{ {
if (d->resource()->version() < WL_DATA_SOURCE_ACTION_SINCE_VERSION) { if (d->resource()->version() < WL_DATA_SOURCE_ACTION_SINCE_VERSION) {
d->supportedDnDActions = DataDeviceManagerInterface::DnDAction::Copy; d->supportedDnDActions = DataDeviceManagerInterface::DnDAction::Copy;

View file

@ -56,8 +56,7 @@ void PrimarySelectionSourceV1InterfacePrivate::zwp_primary_selection_source_v1_d
} }
PrimarySelectionSourceV1Interface::PrimarySelectionSourceV1Interface(PrimarySelectionDeviceManagerV1Interface *parent, ::wl_resource *resource) PrimarySelectionSourceV1Interface::PrimarySelectionSourceV1Interface(PrimarySelectionDeviceManagerV1Interface *parent, ::wl_resource *resource)
: AbstractDataSource(parent) : d(new PrimarySelectionSourceV1InterfacePrivate(this, resource))
, d(new PrimarySelectionSourceV1InterfacePrivate(this, resource))
{ {
} }

View file

@ -1239,7 +1239,7 @@ void SeatInterface::setSelection(AbstractDataSource *selection)
auto cleanup = [this]() { auto cleanup = [this]() {
setSelection(nullptr); setSelection(nullptr);
}; };
connect(selection, &DataSourceInterface::aboutToBeDestroyed, this, cleanup); connect(selection, &AbstractDataSource::aboutToBeDestroyed, this, cleanup);
} }
d->currentSelection = selection; d->currentSelection = selection;
@ -1282,7 +1282,7 @@ void SeatInterface::setPrimarySelection(AbstractDataSource *selection)
auto cleanup = [this]() { auto cleanup = [this]() {
setPrimarySelection(nullptr); setPrimarySelection(nullptr);
}; };
connect(selection, &DataSourceInterface::aboutToBeDestroyed, this, cleanup); connect(selection, &AbstractDataSource::aboutToBeDestroyed, this, cleanup);
} }
d->currentPrimarySelection = selection; d->currentPrimarySelection = selection;