processcontroller: Fix memory leak

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 <jerome.duval@gmail.com>
This commit is contained in:
Murai Takashi 2021-02-16 19:40:06 +09:00 committed by Jérôme Duval
parent c1e6e51a05
commit e5b7c9e313
4 changed files with 8 additions and 3 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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) {

View File

@ -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;