Tracker: Don't crash clicking Open with... menu item

This bug was introduced in hrev47498

The reason Tracker crashed was because OpenWithContainerWindow
had a NULL TargetModel() which we were trying to dereference.

Fix this by creating an empty model in OpenWithContainerWindow. Add an
ASSERT to check that the TargetModel() is not NULL in the future.

Another way to fix this bug would have been to check that TargetModel() wasn't
NULL each time before we use it. I didn't go with that solution because we
assume TargetModel() is not NULL in a lot of places so it would be a lot of work
to check them all. I think it's better to give OpenWithContainerWindow a dummy
model even though it doesn't make sense for it to have one just so that we don't
crash when we try to dereference the pointer.
This commit is contained in:
John Scipione
2014-07-18 10:58:30 -04:00
parent bb804d092e
commit b992df8968
2 changed files with 6 additions and 3 deletions
+5 -2
View File
@@ -2906,6 +2906,9 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
// since we check view mode before display, this should be a radio // since we check view mode before display, this should be a radio
// mode menu // mode menu
Model* targetModel = TargetModel();
ASSERT(targetModel != NULL);
bool needSeparator = true; bool needSeparator = true;
if (IsTrash()) { if (IsTrash()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"), menu->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"),
@@ -2913,7 +2916,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
} else if (IsPrintersDir()) { } else if (IsPrintersDir()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Add printer" B_UTF8_ELLIPSIS), menu->AddItem(new BMenuItem(B_TRANSLATE("Add printer" B_UTF8_ELLIPSIS),
new BMessage(kAddPrinter), 'N')); new BMessage(kAddPrinter), 'N'));
} else if (InTrash() || TargetModel()->IsRoot()) { } else if (InTrash() || targetModel->IsRoot()) {
needSeparator = false; needSeparator = false;
} else { } else {
TemplatesMenu* templatesMenu = new TemplatesMenu(PoseView(), TemplatesMenu* templatesMenu = new TemplatesMenu(PoseView(),
@@ -2945,7 +2948,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
new BMessage(kOpenParentDir), B_UP_ARROW)); new BMessage(kOpenParentDir), B_UP_ARROW));
} }
if (TargetModel()->IsRoot()) { if (targetModel->IsRoot()) {
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new MountMenu(B_TRANSLATE("Mount"))); menu->AddItem(new MountMenu(B_TRANSLATE("Mount")));
} }
+1 -1
View File
@@ -540,7 +540,7 @@ OpenWithContainerWindow::SetCanOpen(bool on)
OpenWithPoseView::OpenWithPoseView(BRect frame, uint32 resizeMask) OpenWithPoseView::OpenWithPoseView(BRect frame, uint32 resizeMask)
: :
BPoseView(0, frame, kListMode, resizeMask), BPoseView(new Model(), frame, kListMode, resizeMask),
fHaveCommonPreferredApp(false), fHaveCommonPreferredApp(false),
fIterator(NULL) fIterator(NULL)
{ {