Tracker: Set message in ModelMenuItem after the try/catch block.

Otherwise the ownership isn't clear: if the exception is thrown
after the item partially initializes, the message might get
deleted by a destructor already. This way, the ownership is clear.
This commit is contained in:
Augustin Cavalier
2025-02-27 22:07:13 -05:00
parent 5341b58f5f
commit 101b09cc05
+5 -5
View File
@@ -259,17 +259,17 @@ AddOneAddOn(const Model* model, const char* name, uint32 shortcut,
{
AddOneAddOnParams* params = (AddOneAddOnParams*)context;
BMessage* message = new BMessage(kLoadAddOn);
message->AddRef("refs", model->EntryRef());
ModelMenuItem* item;
try {
item = new ModelMenuItem(model, name, message, (char)shortcut, modifiers);
item = new ModelMenuItem(model, name, NULL, (char)shortcut, modifiers);
} catch (...) {
delete message;
return;
}
BMessage* message = new BMessage(kLoadAddOn);
message->AddRef("refs", model->EntryRef());
item->SetMessage(message);
const entry_ref* addOnRef = model->EntryRef();
AddOnMenuGenerate(addOnRef, menu, window);