fix(free mem): release QSettings pointer memory

Description: 释放qsettings指针内存

Log: I5M3SK 内存泄露
This commit is contained in:
winnerym 2023-04-12 09:46:15 +08:00
parent 104c0fcc64
commit 23dc81334a
2 changed files with 13 additions and 7 deletions

View File

@ -637,6 +637,10 @@ void Screensaver::setUpdateCenterWidget()
QString languageDirPath=cwdPath+"language/"; QString languageDirPath=cwdPath+"language/";
QString defaultLanguageFilePath=languageDirPath+"screensaver-en_US.ini"; QString defaultLanguageFilePath=languageDirPath+"screensaver-en_US.ini";
qDebug()<<"homePath="<<homePath; qDebug()<<"homePath="<<homePath;
if (qsettings) {
delete qsettings;
qsettings = nullptr;
}
if (!lang.isEmpty()){ if (!lang.isEmpty()){
qDebug()<<"lang = "<<lang; qDebug()<<"lang = "<<lang;
if(lang.contains('.')){ if(lang.contains('.')){
@ -663,19 +667,19 @@ void Screensaver::setUpdateCenterWidget()
} }
if(useJd && jdConfigFileInfo.isFile()){ if(useJd && jdConfigFileInfo.isFile()){
qsettings = new QSettings(jdLanguageFilePath,QSettings::IniFormat); qsettings = new QSettings(jdLanguageFilePath,QSettings::IniFormat,this);
}else if (homeConfigFileInfo.isFile()){ }else if (homeConfigFileInfo.isFile()){
qsettings = new QSettings(homeLanguageFilePath,QSettings::IniFormat); qsettings = new QSettings(homeLanguageFilePath,QSettings::IniFormat,this);
} }
else if(fileInfo.isFile()){ else if(fileInfo.isFile()){
qsettings = new QSettings(languageFilePath,QSettings::IniFormat); qsettings = new QSettings(languageFilePath,QSettings::IniFormat,this);
} }
else{ else{
qsettings = new QSettings(defaultLanguageFilePath,QSettings::IniFormat); qsettings = new QSettings(defaultLanguageFilePath,QSettings::IniFormat,this);
} }
} }
else{ else{
qsettings = new QSettings(defaultLanguageFilePath,QSettings::IniFormat); qsettings = new QSettings(defaultLanguageFilePath,QSettings::IniFormat,this);
} }
qsettings->setIniCodec(QTextCodec::codecForName("UTF-8")); qsettings->setIniCodec(QTextCodec::codecForName("UTF-8"));
@ -773,7 +777,7 @@ void Screensaver::onBackgroundChanged()
} }
void Screensaver::updateCenterWidget(int index) void Screensaver::updateCenterWidget(int index)
{ {
if(!centerWidget ) if(!centerWidget || !qsettings)
return ; return ;
QStringList qlist = qsettings->childGroups(); QStringList qlist = qsettings->childGroups();
@ -1197,6 +1201,8 @@ void Screensaver::setPreviewText(bool bVisible)
void Screensaver::setCenterWidget() void Screensaver::setCenterWidget()
{ {
if (!qsettings)
return ;
QStringList qlist = qsettings->childGroups(); QStringList qlist = qsettings->childGroups();
if(qlist.count()<1) if(qlist.count()<1)
return; return;

View File

@ -111,7 +111,7 @@ private:
QPushButton *settingsButton; QPushButton *settingsButton;
QPushButton *WallpaperButton; QPushButton *WallpaperButton;
QWidget *buttonWidget; QWidget *buttonWidget;
QSettings *qsettings; QSettings *qsettings = nullptr;
MBackground *m_background; MBackground *m_background;