Skip to content

Commit 1cd2097

Browse files
committed
fix: change signal context to prevent dangling pointer
Changed the context parameter in QObject::connect from 'this' to 'deviceItem' for the Device::pairedChanged signal connection. This prevents potential dangling pointer issues when the deviceItem object is deleted while signals are still being processed. The original code used 'this' as context, which could lead to accessing invalid memory if deviceItem was destroyed before the slot execution. Influence: 1. Test Bluetooth device pairing state changes 2. Verify device removal and addition scenarios 3. Check memory usage and stability during device operations 4. Test with multiple Bluetooth adapters and devices 5. Verify no crashes occur when devices are disconnected or removed fix: 更改信号上下文以防止野指针问题 将 QObject::connect 中 Device::pairedChanged 信号的上下文参数从 'this' 改为 'deviceItem'。这可以防止当 deviceItem 对象被删除而信号仍在处理时可 能出现的野指针问题。原始代码使用 'this' 作为上下文,如果 deviceItem 在槽 函数执行前被销毁,可能导致访问无效内存。 Influence: 1. 测试蓝牙设备配对状态变化 2. 验证设备移除和添加场景 3. 检查设备操作期间的内存使用和稳定性 4. 测试多个蓝牙适配器和设备 5. 验证设备断开或移除时不会发生崩溃 PMS: BUG-350859
1 parent 352f45f commit 1cd2097

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

plugins/dde-dock/bluetooth/componments/bluetoothadapteritem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2016 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -227,7 +227,7 @@ void BluetoothAdapterItem::onDeviceAdded(const Device *device)
227227
emit connectDevice(deviceItem->device(), m_adapter);
228228
}
229229
});
230-
connect(device, &Device::pairedChanged, this, [this, deviceItem](const bool paired) {
230+
connect(device, &Device::pairedChanged, deviceItem, [this, deviceItem](const bool paired) {
231231
if (deviceItem && deviceItem->device()) {
232232
PluginStandardItem *item = deviceItem->standardItem();
233233
if (item) {

0 commit comments

Comments
 (0)