Skip to content

Commit

Permalink
fix: tow code blocks cause memory leak.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rb-union authored and deepin-bot[bot] committed Jan 26, 2024
1 parent b88fa7f commit cb3bd72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion deepin-system-monitor-main/model/accounts_info_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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!" ;
Expand Down
5 changes: 4 additions & 1 deletion deepin-system-monitor-main/process/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion deepin-system-monitor-plugin-popup/process/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cb3bd72

Please sign in to comment.