diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-11-10 12:53:02 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-11-11 06:55:41 +0000 |
commit | 78b4a1fb01af9ad3b3395a22f6e396be914b553e (patch) | |
tree | 846fdaea907a70fdc274a1e76642ed5e06622c0d /sd | |
parent | 071e23fee07b92b8f07800cda3ca7e66afe818ae (diff) |
update vclwidget loplugin to find ref-dropping assigment
Look for places where we are accidentally assigning a returned-by-value
VclPtr<T> to a T*, which generally ends up in a use-after-free.
Change-Id: I4f361eaca88820cdb7aa3b8340212db61580fdd9
Reviewed-on: https://gerrit.libreoffice.org/30749
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/ui/framework/factories/FullScreenPane.cxx | 6 | ||||
-rw-r--r-- | sd/source/ui/framework/factories/ViewShellWrapper.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/presenter/PresenterCanvas.cxx | 14 | ||||
-rw-r--r-- | sd/source/ui/presenter/PresenterHelper.cxx | 24 | ||||
-rw-r--r-- | sd/source/ui/sidebar/PanelFactory.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/slidesorter/controller/SlsSlotManager.cxx | 11 | ||||
-rw-r--r-- | sd/source/ui/slidesorter/shell/SlideSorterService.cxx | 4 |
7 files changed, 34 insertions, 33 deletions
diff --git a/sd/source/ui/framework/factories/FullScreenPane.cxx b/sd/source/ui/framework/factories/FullScreenPane.cxx index 941d938282a3..4181ba3c7b84 100644 --- a/sd/source/ui/framework/factories/FullScreenPane.cxx +++ b/sd/source/ui/framework/factories/FullScreenPane.cxx @@ -193,13 +193,13 @@ IMPL_LINK(FullScreenPane, WindowEventHandler, VclWindowEvent&, rEvent, void) Reference<rendering::XCanvas> FullScreenPane::CreateCanvas() throw (RuntimeException) { - vcl::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow); - if (pWindow != nullptr) + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(mxWindow); + if (pWindow) { Sequence<Any> aArg (5); // common: first any is VCL pointer to window (for VCL canvas) - aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow)); + aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow.get())); aArg[1] = Any(); aArg[2] = makeAny(css::awt::Rectangle()); aArg[3] = makeAny(false); diff --git a/sd/source/ui/framework/factories/ViewShellWrapper.cxx b/sd/source/ui/framework/factories/ViewShellWrapper.cxx index 1c4be5b1eb60..c89c874aa524 100644 --- a/sd/source/ui/framework/factories/ViewShellWrapper.cxx +++ b/sd/source/ui/framework/factories/ViewShellWrapper.cxx @@ -204,8 +204,8 @@ sal_Bool SAL_CALL ViewShellWrapper::relocateToAnchor ( if (mpViewShell.get() != nullptr) { - vcl::Window* pWindow = VCLUnoHelper::GetWindow(xPane->getWindow()); - if (pWindow != nullptr && mpViewShell->RelocateToParentWindow(pWindow)) + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xPane->getWindow()); + if (pWindow && mpViewShell->RelocateToParentWindow(pWindow)) { bResult = true; diff --git a/sd/source/ui/presenter/PresenterCanvas.cxx b/sd/source/ui/presenter/PresenterCanvas.cxx index fd42bdc207b9..6333a536123e 100644 --- a/sd/source/ui/presenter/PresenterCanvas.cxx +++ b/sd/source/ui/presenter/PresenterCanvas.cxx @@ -631,9 +631,9 @@ awt::Point PresenterCanvas::GetOffset (const Reference<awt::XWindow>& rxBaseWind mbOffsetUpdatePending = false; if (mxWindow.is() && rxBaseWindow.is()) { - vcl::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow); - vcl::Window* pSharedWindow = VCLUnoHelper::GetWindow(rxBaseWindow); - if (pWindow!=nullptr && pSharedWindow!=nullptr) + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(mxWindow); + VclPtr<vcl::Window> pSharedWindow = VCLUnoHelper::GetWindow(rxBaseWindow); + if (pWindow && pSharedWindow) { Rectangle aBox = pWindow->GetWindowExtentsRelative(pSharedWindow); @@ -652,12 +652,12 @@ awt::Point PresenterCanvas::GetOffset (const Reference<awt::XWindow>& rxBaseWind { ::basegfx::B2DRectangle aClipRectangle; - vcl::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow); - if (pWindow == nullptr) + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(mxWindow); + if (!pWindow) return ::basegfx::B2DRectangle(); - vcl::Window* pSharedWindow = VCLUnoHelper::GetWindow(mxSharedWindow); - if (pSharedWindow == nullptr) + VclPtr<vcl::Window> pSharedWindow = VCLUnoHelper::GetWindow(mxSharedWindow); + if (!pSharedWindow) return ::basegfx::B2DRectangle(); // Get the bounding box of the window and create a range in the diff --git a/sd/source/ui/presenter/PresenterHelper.cxx b/sd/source/ui/presenter/PresenterHelper.cxx index d103a84fa0db..7a7f4856da53 100644 --- a/sd/source/ui/presenter/PresenterHelper.cxx +++ b/sd/source/ui/presenter/PresenterHelper.cxx @@ -149,13 +149,13 @@ Reference<rendering::XCanvas> SAL_CALL PresenterHelper::createCanvas ( // No shared window is given or an explicit canvas service name is // specified. Create a new canvas. - vcl::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); - if (pWindow != nullptr) + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rxWindow); + if (pWindow) { Sequence<Any> aArg (5); // common: first any is VCL pointer to window (for VCL canvas) - aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow)); + aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow.get())); aArg[1] = Any(); aArg[2] = makeAny(css::awt::Rectangle()); aArg[3] = makeAny(false); @@ -179,8 +179,8 @@ void SAL_CALL PresenterHelper::toTop ( const Reference<awt::XWindow>& rxWindow) throw (css::uno::RuntimeException, std::exception) { - vcl::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); - if (pWindow != nullptr) + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rxWindow); + if (pWindow) { pWindow->ToTop(); pWindow->SetZOrder(nullptr, ZOrderFlags::Last); @@ -426,8 +426,8 @@ void SAL_CALL PresenterHelper::captureMouse ( ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex()); // Capture the mouse (if not already done.) - vcl::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); - if (pWindow != nullptr && ! pWindow->IsMouseCaptured()) + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rxWindow); + if (pWindow && ! pWindow->IsMouseCaptured()) { pWindow->CaptureMouse(); } @@ -439,8 +439,8 @@ void SAL_CALL PresenterHelper::releaseMouse (const Reference<awt::XWindow>& rxWi ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex()); // Release the mouse (if not already done.) - vcl::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); - if (pWindow != nullptr && pWindow->IsMouseCaptured()) + VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(rxWindow); + if (pWindow && pWindow->IsMouseCaptured()) { pWindow->ReleaseMouse(); } @@ -451,9 +451,9 @@ awt::Rectangle PresenterHelper::getWindowExtentsRelative ( const Reference<awt::XWindow>& rxParentWindow) throw (RuntimeException, std::exception) { - vcl::Window* pChildWindow = VCLUnoHelper::GetWindow(rxChildWindow); - vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(rxParentWindow); - if (pChildWindow!=nullptr && pParentWindow!=nullptr) + VclPtr<vcl::Window> pChildWindow = VCLUnoHelper::GetWindow(rxChildWindow); + VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(rxParentWindow); + if (pChildWindow && pParentWindow) { Rectangle aBox (pChildWindow->GetWindowExtentsRelative(pParentWindow)); return awt::Rectangle(aBox.Left(),aBox.Top(),aBox.GetWidth(),aBox.GetHeight()); diff --git a/sd/source/ui/sidebar/PanelFactory.cxx b/sd/source/ui/sidebar/PanelFactory.cxx index 28f94a9aa2e4..6c83d3bd8529 100644 --- a/sd/source/ui/sidebar/PanelFactory.cxx +++ b/sd/source/ui/sidebar/PanelFactory.cxx @@ -80,8 +80,8 @@ Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement ( Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>())); // Throw exceptions when the arguments are not as expected. - vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); - if ( ! xParentWindow.is() || pParentWindow==nullptr) + VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); + if ( ! xParentWindow.is() || !pParentWindow) throw RuntimeException( "PanelFactory::createUIElement called without ParentWindow"); if ( ! xFrame.is()) diff --git a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx index 8998c0cc6046..da82353cd0e4 100644 --- a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx +++ b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx @@ -274,11 +274,12 @@ void SlotManager::FuTemporary (SfxRequest& rRequest) { #ifdef ENABLE_SDREMOTE SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create(); - VclAbstractDialog* pDlg = pFact ? - pFact->CreateRemoteDialog( mrSlideSorter.GetContentWindow() ) : - nullptr; - if (pDlg) - pDlg->Execute(); + if (pFact) + { + ScopedVclPtr<VclAbstractDialog> pDlg( pFact->CreateRemoteDialog( mrSlideSorter.GetContentWindow() ) ); + if (pDlg) + pDlg->Execute(); + } #endif } break; diff --git a/sd/source/ui/slidesorter/shell/SlideSorterService.cxx b/sd/source/ui/slidesorter/shell/SlideSorterService.cxx index ddc36a5c50cd..35f53ae46036 100644 --- a/sd/source/ui/slidesorter/shell/SlideSorterService.cxx +++ b/sd/source/ui/slidesorter/shell/SlideSorterService.cxx @@ -89,11 +89,11 @@ void SAL_CALL SlideSorterService::initialize (const Sequence<Any>& rArguments) // Get the parent window. mxParentWindow.set(rArguments[2], UNO_QUERY_THROW); - vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(mxParentWindow); + VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(mxParentWindow); mxParentWindow->addWindowListener(this); - if (pBase != nullptr && pParentWindow!=nullptr) + if (pBase != nullptr && pParentWindow) mpSlideSorter = SlideSorter::CreateSlideSorter( *pBase, nullptr, |