LayoutBuilder.h: Fix use after free

Fix 'item' is used after delete.
Pointed out by Clang Static Analyzer.

Change-Id: I8eca3084c97b37015a2da1b96119a458d4eb9aa7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3392
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Reviewed-by: John Scipione <jscipione@gmail.com>
This commit is contained in:
Murai Takashi 2020-11-13 21:27:04 +09:00 committed by Adrien Destugues
parent a6c8647e0a
commit cb5156f081

View File

@ -1737,8 +1737,10 @@ Menu<ParentBuilder>::AddItem(const char* label, BMessage* message,
char shortcut, uint32 modifiers)
{
BMenuItem* item = new BMenuItem(label, message, shortcut, modifiers);
if (!fMenu->AddItem(item))
if (!fMenu->AddItem(item)) {
delete item;
item = NULL;
}
return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
}
@ -1758,8 +1760,10 @@ Menu<ParentBuilder>::AddItem(const char* label, uint32 messageWhat,
throw;
}
if (!fMenu->AddItem(item))
if (!fMenu->AddItem(item)) {
delete item;
item = NULL;
}
return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
}