From e5b7c9e313bfff75b75d69cf506a8898fc44f286 Mon Sep 17 00:00:00 2001 From: Murai Takashi Date: Tue, 16 Feb 2021 19:40:06 +0900 Subject: [PATCH] processcontroller: Fix memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When getting icon is failed, get_team_name_and_icon() does not return false, so bitmap allocated to infoPack.team_icon can be leaked. * Delete bitmap in get_team_name_and_icon(), not in caller. * Return false when getiing icon is failed. Change-Id: Ib65065b59b70cd839e6deda4e1142bd104072d84 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3744 Reviewed-by: Jérôme Duval --- src/apps/processcontroller/MemoryBarMenu.cpp | 1 - src/apps/processcontroller/QuitMenu.cpp | 3 ++- src/apps/processcontroller/TeamBarMenu.cpp | 1 - src/apps/processcontroller/Utilities.cpp | 6 ++++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/apps/processcontroller/MemoryBarMenu.cpp b/src/apps/processcontroller/MemoryBarMenu.cpp index 52c561fea9..0aa5b4f146 100644 --- a/src/apps/processcontroller/MemoryBarMenu.cpp +++ b/src/apps/processcontroller/MemoryBarMenu.cpp @@ -134,7 +134,6 @@ MemoryBarMenu::Pulse() fTeamList[j] = infos.team_info.team; if (!get_team_name_and_icon(infos, true)) { // the team is already gone! - delete infos.team_icon; fTeamList[j] = -1; } else { if (!item && firstRecycle < lastRecycle) diff --git a/src/apps/processcontroller/QuitMenu.cpp b/src/apps/processcontroller/QuitMenu.cpp index ee4192dc98..369bbab0db 100644 --- a/src/apps/processcontroller/QuitMenu.cpp +++ b/src/apps/processcontroller/QuitMenu.cpp @@ -106,9 +106,10 @@ QuitMenu::AddTeam(team_id tmid) else { info_pack infos; if (get_team_info(tmid, &infos.team_info) == B_OK - && get_team_name_and_icon(infos, true)) + && get_team_name_and_icon(infos, true)) { item = new QuitMenuItem(tmid, infos.team_icon, infos.team_name, message, true); + } } if (item) { item->SetTarget(gPCView); diff --git a/src/apps/processcontroller/TeamBarMenu.cpp b/src/apps/processcontroller/TeamBarMenu.cpp index f65ef1926e..aecfe36871 100644 --- a/src/apps/processcontroller/TeamBarMenu.cpp +++ b/src/apps/processcontroller/TeamBarMenu.cpp @@ -117,7 +117,6 @@ TeamBarMenu::Pulse() fTeamList[j] = infos.team_info.team; if (!get_team_name_and_icon(infos, true)) { // the team is already gone! - delete infos.team_icon; fTeamList[j] = -1; } else { if (!item && firstRecycle < lastRecycle) { diff --git a/src/apps/processcontroller/Utilities.cpp b/src/apps/processcontroller/Utilities.cpp index 60fef30179..470247b3b3 100644 --- a/src/apps/processcontroller/Utilities.cpp +++ b/src/apps/processcontroller/Utilities.cpp @@ -67,6 +67,12 @@ get_team_name_and_icon(info_pack& infoPack, bool icon) B_MINI_ICON) != B_OK) { BMimeType genericAppType(B_APP_MIME_TYPE); status = genericAppType.GetIcon(infoPack.team_icon, B_MINI_ICON); + // failed to get icon + if (status != B_OK) { + delete infoPack.team_icon; + infoPack.team_icon = NULL; + return false; + } } } else infoPack.team_icon = NULL;