fix: 释放语音服务插件资源#694
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider making
m_settingsa childQObject(e.g., by passingthistofromJsonFileor callingm_settings->setParent(this)) so that you can rely on Qt’s parent-child lifetime management instead of manually deleting the pointer in the destructor. - Once
m_voiceis parented toMusicVoiceService, ensure there are no other manual deletions or ownership transfers ofm_voiceelsewhere in the codebase to avoid double-free or dangling pointer issues.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider making `m_settings` a child `QObject` (e.g., by passing `this` to `fromJsonFile` or calling `m_settings->setParent(this)`) so that you can rely on Qt’s parent-child lifetime management instead of manually deleting the pointer in the destructor.
- Once `m_voice` is parented to `MusicVoiceService`, ensure there are no other manual deletions or ownership transfers of `m_voice` elsewhere in the codebase to avoid double-free or dangling pointer issues.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Log: 修复MusicVoiceService未释放VoicePlugin的问题 Task: https://pms.uniontech.com/task-view-390625.html Influence: 服务释放时通过Qt父子对象机制回收VoicePlugin,并释放内部
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 diff --git a/src/libmusic-plugin/musicvoiceservice.cpp b/src/libmusic-plugin/musicvoiceservice.cpp
index 7c6754f40..67344af1e 100644
--- a/src/libmusic-plugin/musicvoiceservice.cpp
+++ b/src/libmusic-plugin/musicvoiceservice.cpp
@@ -8,7 +8,7 @@
MusicVoiceService::MusicVoiceService()
{
- m_voice = new VoicePlugin();
+ m_voice = new VoicePlugin(this);
}
diff --git a/src/libmusic-plugin/voiceplugin.cpp b/src/libmusic-plugin/voiceplugin.cpp
index 81de7f234..58a59ac7c 100644
--- a/src/libmusic-plugin/voiceplugin.cpp
+++ b/src/libmusic-plugin/voiceplugin.cpp
@@ -21,6 +21,9 @@
VoicePlugin::VoicePlugin(QObject *parent): QObject(parent)
{
m_settings = Dtk::Core::DSettings::fromJsonFile(":/speech/data/deepin-music-speechconfig.json");
+ if (m_settings) {
+ m_settings->setParent(this);
+ }
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, Resurgamz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
Log: 修复MusicVoiceService未释放VoicePlugin的问题
Task: https://pms.uniontech.com/task-view-390625.html
Influence: 服务释放时通过Qt父子对象机制回收VoicePlugin,并释放内部
Summary by Sourcery
Ensure VoicePlugin instances are properly parented and release their internal resources on destruction to prevent leaks.
Bug Fixes: