From cb3bd7243e168ea99c8ed2a09ff11d0cac61c03a Mon Sep 17 00:00:00 2001 From: renbin Date: Fri, 26 Jan 2024 10:59:12 +0800 Subject: [PATCH] fix: tow code blocks cause memory leak. 1. QList loops to append repeated data; 2. Forgot to release temporary malloc data. Log: fix two code block memory leaks. Bug: https://pms.uniontech.com/bug-view-239575.html --- deepin-system-monitor-main/model/accounts_info_model.cpp | 6 +++++- deepin-system-monitor-main/process/process.cpp | 5 ++++- deepin-system-monitor-plugin-popup/process/process.cpp | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/deepin-system-monitor-main/model/accounts_info_model.cpp b/deepin-system-monitor-main/model/accounts_info_model.cpp index 790299fa..29412ebb 100644 --- a/deepin-system-monitor-main/model/accounts_info_model.cpp +++ b/deepin-system-monitor-main/model/accounts_info_model.cpp @@ -72,7 +72,10 @@ void AccountsInfoModel::onSessionRemoved(const QString &in0, const QDBusObjectPa void AccountsInfoModel::updateUserList(const QStringList &userPathList) { qInfo() << "AccountsInfoModel updateUserList line 61" << "updateUserList begins!" ; + // 释放构造对象 + qDeleteAll(m_userMap.values()); m_userMap.clear(); + for (QString userPath : userPathList) { QDBusInterface *userDBus = new QDBusInterface(common::systemInfo().AccountsService, userPath, common::systemInfo().UserInterface, QDBusConnection::systemBus(), this); User *newUser = new User; @@ -90,10 +93,11 @@ void AccountsInfoModel::updateUserList(const QStringList &userPathList) } qInfo() << "AccountsInfoModel updateUserList line 78" << "get user info of :" << newUser->name(); m_userMap.insert(newUser->name(), newUser); + + delete userDBus; } } - void AccountsInfoModel::updateUserOnlineStatus() { qInfo() << "AccountsInfoModel updateUserOnlineStatus line 88" << "updateUserOnlineStatus begins!" ; diff --git a/deepin-system-monitor-main/process/process.cpp b/deepin-system-monitor-main/process/process.cpp index b3f5cdc6..b47b204e 100644 --- a/deepin-system-monitor-main/process/process.cpp +++ b/deepin-system-monitor-main/process/process.cpp @@ -638,7 +638,10 @@ void Process::readSockInodes() if (!stat(fdp, &sbuf)) { // get inode if it's a socket descriptor if (S_ISSOCK(sbuf.st_mode)) { - d->sockInodes << sbuf.st_ino; + // not append repeat data, may memory leak. + if (!d->sockInodes.contains(sbuf.st_ino)) { + d->sockInodes << sbuf.st_ino; + } } } // ::if(stat) } // ::if(isdigit) diff --git a/deepin-system-monitor-plugin-popup/process/process.cpp b/deepin-system-monitor-plugin-popup/process/process.cpp index faa20e98..773a8f40 100644 --- a/deepin-system-monitor-plugin-popup/process/process.cpp +++ b/deepin-system-monitor-plugin-popup/process/process.cpp @@ -536,7 +536,9 @@ void Process::readSockInodes() if (!stat(fdp, &sbuf)) { // get inode if it's a socket descriptor if (S_ISSOCK(sbuf.st_mode)) { - d->sockInodes << sbuf.st_ino; + if (!d->sockInodes.contains(sbuf.st_ino)) { + d->sockInodes << sbuf.st_ino; + } } } // ::if(stat) } // ::if(isdigit)