Skip to content

Commit 2d49c07

Browse files
18202781743deepin-bot[bot]
authored andcommitted
fix: replace QScopedPointer with raw pointer for DSGConfigManager
1. Changed DBusBackend::config from QScopedPointer<DSGConfigManager> to raw pointer DSGConfigManager* 2. Initialize config to nullptr in constructor initializer list 3. Replace config.reset(new DSGConfigManager(...)) with direct new operator 4. Replace config.reset() with config->deleteLater() and config = nullptr in error handling 5. Replace config.data() with config in QObject::connect call 6. This eliminates redundant ownership management since DSGConfigManager is already a QObject with its own lifetime management Log: Fixed potential double deletion issue with DSGConfigManager object Influence: 1. Test DConfig functionality with DBus backend to ensure no memory leaks 2. Verify that valueChanged signals are still properly connected and emitted 3. Test error scenarios where DSGConfigManager creation fails 4. Verify object cleanup when DConfig is destroyed 5. Test with multiple DConfig instances to ensure no interference fix: 将 DSGConfigManager 的 QScopedPointer 替换为原始指针 1. 将 DBusBackend::config 从 QScopedPointer<DSGConfigManager> 改为原始指 针 DSGConfigManager* 2. 在构造函数初始化列表中初始化 config 为 nullptr 3. 将 config.reset(new DSGConfigManager(...)) 替换为直接使用 new 操作符 4. 在错误处理中将 config.reset() 替换为 config->deleteLater() 和 config = nullptr 5. 在 QObject::connect 调用中将 config.data() 替换为 config 6. 消除了重复的所有权管理,因为 DSGConfigManager 已经是具有自身生命周期 管理的 QObject Log: 修复了 DSGConfigManager 对象可能被重复删除的问题 Influence: 1. 测试使用 DBus 后端的 DConfig 功能,确保没有内存泄漏 2. 验证 valueChanged 信号是否仍然正确连接和发射 3. 测试 DSGConfigManager 创建失败的场景 4. 验证 DConfig 销毁时的对象清理 5. 测试多个 DConfig 实例以确保没有相互干扰 PMS: BUG-335881
1 parent faab807 commit 2d49c07

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/dconfig.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ class Q_DECL_HIDDEN DBusBackend : public DConfigBackend
296296
{
297297
public:
298298
explicit DBusBackend(DConfigPrivate* o):
299-
owner(o)
299+
owner(o),
300+
config(nullptr)
300301
{
301302
}
302303

@@ -345,14 +346,15 @@ class Q_DECL_HIDDEN DBusBackend : public DConfigBackend
345346
return false;
346347
} else {
347348
qCDebug(cfLog, "dbus path=\"%s\"", qPrintable(path));
348-
config.reset(new DSGConfigManager(DSG_CONFIG_MANAGER, path,
349-
QDBusConnection::systemBus(), owner->q_func()));
349+
config = new DSGConfigManager(DSG_CONFIG_MANAGER, path,
350+
QDBusConnection::systemBus(), owner->q_func());
350351
if (!config->isValid()) {
351352
qCWarning(cfLog, "Can't acquire config path=\"%s\"", qPrintable(path));
352-
config.reset();
353+
config->deleteLater();
354+
config = nullptr;
353355
return false;
354356
} else {
355-
QObject::connect(config.data(), &DSGConfigManager::valueChanged, owner->q_func(), &DConfig::valueChanged);
357+
QObject::connect(config, &DSGConfigManager::valueChanged, owner->q_func(), &DConfig::valueChanged);
356358
}
357359
}
358360
return true;
@@ -456,7 +458,7 @@ class Q_DECL_HIDDEN DBusBackend : public DConfigBackend
456458
}
457459

458460
private:
459-
QScopedPointer<DSGConfigManager> config;
461+
DSGConfigManager *config;
460462
DConfigPrivate* owner;
461463
};
462464

0 commit comments

Comments
 (0)