From b992df8968fcc9e83f0e247966571196ce5c90c9 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 18 Jul 2014 10:58:30 -0400 Subject: [PATCH] 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. --- src/kits/tracker/ContainerWindow.cpp | 7 +++++-- src/kits/tracker/OpenWithWindow.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/kits/tracker/ContainerWindow.cpp b/src/kits/tracker/ContainerWindow.cpp index 0626900909..35023981b0 100644 --- a/src/kits/tracker/ContainerWindow.cpp +++ b/src/kits/tracker/ContainerWindow.cpp @@ -2906,6 +2906,9 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu) // since we check view mode before display, this should be a radio // mode menu + Model* targetModel = TargetModel(); + ASSERT(targetModel != NULL); + bool needSeparator = true; if (IsTrash()) { menu->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"), @@ -2913,7 +2916,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu) } else if (IsPrintersDir()) { menu->AddItem(new BMenuItem(B_TRANSLATE("Add printer" B_UTF8_ELLIPSIS), new BMessage(kAddPrinter), 'N')); - } else if (InTrash() || TargetModel()->IsRoot()) { + } else if (InTrash() || targetModel->IsRoot()) { needSeparator = false; } else { TemplatesMenu* templatesMenu = new TemplatesMenu(PoseView(), @@ -2945,7 +2948,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu) new BMessage(kOpenParentDir), B_UP_ARROW)); } - if (TargetModel()->IsRoot()) { + if (targetModel->IsRoot()) { menu->AddSeparatorItem(); menu->AddItem(new MountMenu(B_TRANSLATE("Mount"))); } diff --git a/src/kits/tracker/OpenWithWindow.cpp b/src/kits/tracker/OpenWithWindow.cpp index 1ce74a3635..615a6e926b 100644 --- a/src/kits/tracker/OpenWithWindow.cpp +++ b/src/kits/tracker/OpenWithWindow.cpp @@ -540,7 +540,7 @@ OpenWithContainerWindow::SetCanOpen(bool on) OpenWithPoseView::OpenWithPoseView(BRect frame, uint32 resizeMask) : - BPoseView(0, frame, kListMode, resizeMask), + BPoseView(new Model(), frame, kListMode, resizeMask), fHaveCommonPreferredApp(false), fIterator(NULL) {