Bug Summary

File:home/maarten/src/libreoffice/core/framework/source/layoutmanager/helpers.cxx
Warning:line 114, column 5
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name helpers.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D FWK_DLLIMPLEMENTATION -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/framework/source/inc -I /home/maarten/src/libreoffice/core/framework/inc -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/framework/source/layoutmanager/helpers.cxx

/home/maarten/src/libreoffice/core/framework/source/layoutmanager/helpers.cxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "helpers.hxx"
21
22#include <com/sun/star/ui/DockingArea.hpp>
23#include <com/sun/star/awt/Toolkit.hpp>
24#include <com/sun/star/awt/XTopWindow.hpp>
25#include <com/sun/star/frame/DispatchHelper.hpp>
26#include <com/sun/star/awt/XDockableWindow.hpp>
27#include <com/sun/star/awt/XDockableWindowListener.hpp>
28#include <com/sun/star/awt/XWindowListener.hpp>
29#include <com/sun/star/ui/XUIElement.hpp>
30
31#include <unotools/mediadescriptor.hxx>
32#include <vcl/svapp.hxx>
33#include <toolkit/helper/vclunohelper.hxx>
34
35using namespace com::sun::star;
36
37namespace framework
38{
39
40bool hasEmptySize( const css::awt::Size& rSize )
41{
42 return ( rSize.Width == 0 ) && ( rSize.Height == 0 );
43}
44
45bool hasDefaultPosValue( const css::awt::Point& rPos )
46{
47 return (( rPos.X == SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) ) || ( rPos.Y == SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) ));
48}
49
50bool isDefaultPos( const css::awt::Point& rPos )
51{
52 return (( rPos.X == SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) ) && ( rPos.Y == SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) ));
53}
54
55bool isReverseOrderDockingArea( const sal_Int32 nDockArea )
56{
57 ui::DockingArea eDockArea = static_cast< ui::DockingArea >( nDockArea );
58 return (( eDockArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) ||
59 ( eDockArea == ui::DockingArea_DOCKINGAREA_RIGHT ));
60}
61
62bool isToolboxHorizontalAligned( ToolBox const * pToolBox )
63{
64 if ( pToolBox )
65 return (( pToolBox->GetAlign() == WindowAlign::Top ) || ( pToolBox->GetAlign() == WindowAlign::Bottom ));
66 return false;
67}
68
69bool isHorizontalDockingArea( const ui::DockingArea& nDockingArea )
70{
71 return (( nDockingArea == ui::DockingArea_DOCKINGAREA_TOP ) ||
72 ( nDockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ));
73}
74
75bool isHorizontalDockingArea( const sal_Int32 nDockArea )
76{
77 return isHorizontalDockingArea(static_cast< ui::DockingArea >( nDockArea ));
78}
79
80OUString retrieveToolbarNameFromHelpURL( vcl::Window* pWindow )
81{
82 OUString aToolbarName;
83
84 if ( pWindow->GetType() == WindowType::TOOLBOX )
85 {
86 ToolBox* pToolBox = dynamic_cast<ToolBox *>( pWindow );
87 if ( pToolBox )
88 {
89 aToolbarName = OStringToOUString( pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) );
90 sal_Int32 i = aToolbarName.lastIndexOf( ':' );
91 if ( !aToolbarName.isEmpty() && ( i > 0 ) && (( i + 1 ) < aToolbarName.getLength() ))
92 aToolbarName = aToolbarName.copy( i+1 ); // Remove ".HelpId:" protocol from toolbar name
93 else
94 aToolbarName.clear();
95 }
96 }
97 return aToolbarName;
98}
99
100ToolBox* getToolboxPtr( vcl::Window* pWindow )
101{
102 ToolBox* pToolbox(nullptr);
103 if ( pWindow->GetType() == WindowType::TOOLBOX )
104 pToolbox = dynamic_cast<ToolBox*>( pWindow );
105 return pToolbox;
106}
107
108vcl::Window* getWindowFromXUIElement( const uno::Reference< ui::XUIElement >& xUIElement )
109{
110 SolarMutexGuard aGuard;
111 uno::Reference< awt::XWindow > xWindow;
112 if ( xUIElement.is() )
1
Taking false branch
113 xWindow.set( xUIElement->getRealInterface(), uno::UNO_QUERY );
114 return VCLUnoHelper::GetWindow( xWindow );
2
Calling implicit destructor for 'VclPtr<vcl::Window>'
3
Calling '~Reference'
11
Returning from '~Reference'
12
Returning from destructor for 'VclPtr<vcl::Window>'
13
Use of memory after it is freed
115}
116
117SystemWindow* getTopSystemWindow( const uno::Reference< awt::XWindow >& xWindow )
118{
119 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
120 while ( pWindow && !pWindow->IsSystemWindow() )
121 pWindow = pWindow->GetParent();
122
123 if ( pWindow )
124 return static_cast<SystemWindow *>(pWindow.get());
125 else
126 return nullptr;
127}
128
129void setZeroRectangle( ::tools::Rectangle& rRect )
130{
131 rRect.setX(0);
132 rRect.setY(0);
133 rRect.setWidth(0);
134 rRect.setHeight(0);
135}
136
137// ATTENTION!
138// This value is directly copied from the sfx2 project.
139// You have to change BOTH values, see sfx2/inc/sfx2/sfxsids.hrc (SID_DOCKWIN_START)
140const sal_Int32 DOCKWIN_ID_BASE = 9800;
141
142bool lcl_checkUIElement(const uno::Reference< ui::XUIElement >& xUIElement, awt::Rectangle& _rPosSize, uno::Reference< awt::XWindow >& _xWindow)
143{
144 bool bRet = xUIElement.is();
145 if ( bRet )
146 {
147 SolarMutexGuard aGuard;
148 _xWindow.set( xUIElement->getRealInterface(), uno::UNO_QUERY );
149 _rPosSize = _xWindow->getPosSize();
150
151 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( _xWindow );
152 if ( pWindow->GetType() == WindowType::TOOLBOX )
153 {
154 ::Size aSize = static_cast<ToolBox*>(pWindow.get())->CalcWindowSizePixel( 1 );
155 _rPosSize.Width = aSize.Width();
156 _rPosSize.Height = aSize.Height();
157 }
158 } // if ( xUIElement.is() )
159 return bRet;
160}
161
162uno::Reference< awt::XWindowPeer > createToolkitWindow( const uno::Reference< uno::XComponentContext >& rxContext, const uno::Reference< awt::XWindowPeer >& rParent, const char* pService )
163{
164 uno::Reference< awt::XToolkit2 > xToolkit = awt::Toolkit::create( rxContext );
165
166 // describe window properties.
167 css::awt::WindowDescriptor aDescriptor;
168 aDescriptor.Type = awt::WindowClass_SIMPLE;
169 aDescriptor.WindowServiceName = OUString::createFromAscii( pService );
170 aDescriptor.ParentIndex = -1;
171 aDescriptor.Parent = rParent;
172 aDescriptor.Bounds = awt::Rectangle(0,0,0,0);
173 aDescriptor.WindowAttributes = 0;
174
175 // create an awt window
176 uno::Reference< awt::XWindowPeer > xPeer = xToolkit->createWindow( aDescriptor );
177
178 return xPeer;
179}
180
181// convert alignment constant to vcl's WindowAlign type
182WindowAlign ImplConvertAlignment( ui::DockingArea aAlignment )
183{
184 if ( aAlignment == ui::DockingArea_DOCKINGAREA_LEFT )
185 return WindowAlign::Left;
186 else if ( aAlignment == ui::DockingArea_DOCKINGAREA_RIGHT )
187 return WindowAlign::Right;
188 else if ( aAlignment == ui::DockingArea_DOCKINGAREA_TOP )
189 return WindowAlign::Top;
190 else
191 return WindowAlign::Bottom;
192}
193
194OUString getElementTypeFromResourceURL( const OUString& aResourceURL )
195{
196 OUString aUIResourceURL( UIRESOURCE_URL"private:resource" );
197 if ( aResourceURL.startsWith( aUIResourceURL ) )
198 {
199 sal_Int32 nIndex{ aUIResourceURL.getLength() };
200 return aResourceURL.getToken( 1, '/', nIndex );
201 }
202
203 return OUString();
204}
205
206void parseResourceURL( const OUString& aResourceURL, OUString& aElementType, OUString& aElementName )
207{
208 OUString aUIResourceURL( UIRESOURCE_URL"private:resource" );
209 if ( aResourceURL.startsWith( aUIResourceURL ) )
210 {
211 sal_Int32 nIndex{ aUIResourceURL.getLength() };
212 aElementType = aResourceURL.getToken( 1, '/', nIndex );
213 aElementName = aResourceURL.getToken( 0, '/', nIndex );
214 }
215}
216
217css::awt::Rectangle putRectangleValueToAWT( const ::tools::Rectangle& rRect )
218{
219 css::awt::Rectangle aRect;
220 aRect.X = rRect.Left();
221 aRect.Y = rRect.Top();
222 aRect.Width = rRect.Right();
223 aRect.Height = rRect.Bottom();
224
225 return aRect;
226}
227
228::tools::Rectangle putAWTToRectangle( const css::awt::Rectangle& rRect )
229{
230 ::tools::Rectangle aRect;
231 aRect.SetLeft( rRect.X );
232 aRect.SetTop( rRect.Y );
233 aRect.SetRight( rRect.Width );
234 aRect.SetBottom( rRect.Height );
235
236 return aRect;
237}
238
239bool equalRectangles( const css::awt::Rectangle& rRect1,
240 const css::awt::Rectangle& rRect2 )
241{
242 return (( rRect1.X == rRect2.X ) &&
243 ( rRect1.Y == rRect2.Y ) &&
244 ( rRect1.Width == rRect2.Width ) &&
245 ( rRect1.Height == rRect2.Height ));
246}
247
248uno::Reference< frame::XModel > impl_getModelFromFrame( const uno::Reference< frame::XFrame >& rFrame )
249{
250 // Query for the model to get check the context information
251 uno::Reference< frame::XModel > xModel;
252 if ( rFrame.is() )
253 {
254 uno::Reference< frame::XController > xController = rFrame->getController();
255 if ( xController.is() )
256 xModel = xController->getModel();
257 }
258
259 return xModel;
260}
261
262bool implts_isPreviewModel( const uno::Reference< frame::XModel >& xModel )
263{
264 if ( xModel.is() )
265 {
266 utl::MediaDescriptor aDesc( xModel->getArgs() );
267 return aDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_PREVIEW(), false);
268 }
269 else
270 return false;
271}
272
273bool implts_isFrameOrWindowTop( const uno::Reference< frame::XFrame >& xFrame )
274{
275 if (xFrame->isTop())
276 return true;
277
278 uno::Reference< awt::XTopWindow > xWindowCheck(xFrame->getContainerWindow(), uno::UNO_QUERY); // don't use _THROW here ... it's a check only
279 if (xWindowCheck.is())
280 {
281 // #i76867# top and system window is required.
282 SolarMutexGuard aGuard;
283 uno::Reference< awt::XWindow > xWindow( xWindowCheck, uno::UNO_QUERY );
284 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
285 return pWindow && pWindow->IsSystemWindow();
286 }
287
288 return false;
289}
290
291void impl_setDockingWindowVisibility( const css::uno::Reference< css::uno::XComponentContext>& rxContext, const css::uno::Reference< css::frame::XFrame >& rFrame, const OUString& rDockingWindowName, bool bVisible )
292{
293 sal_Int32 nID = rDockingWindowName.toInt32();
294 sal_Int32 nIndex = nID - DOCKWIN_ID_BASE;
295
296 css::uno::Reference< css::frame::XDispatchProvider > xProvider(rFrame, css::uno::UNO_QUERY);
297 if ( !(nIndex >= 0 && xProvider.is()) )
298 return;
299
300 OUString aDockWinArgName = "DockingWindow" + OUString::number( nIndex );
301
302 css::uno::Sequence< css::beans::PropertyValue > aArgs(1);
303 aArgs[0].Name = aDockWinArgName;
304 aArgs[0].Value <<= bVisible;
305
306 css::uno::Reference< css::frame::XDispatchHelper > xDispatcher = css::frame::DispatchHelper::create( rxContext );
307
308 OUString aDockWinCommand = ".uno:" + aDockWinArgName;
309 xDispatcher->executeDispatch(
310 xProvider,
311 aDockWinCommand,
312 "_self",
313 0,
314 aArgs);
315}
316
317void impl_addWindowListeners(
318 const css::uno::Reference< css::uno::XInterface >& xThis,
319 const css::uno::Reference< css::ui::XUIElement >& xUIElement )
320{
321 css::uno::Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
322 css::uno::Reference< css::awt::XDockableWindow > xDockWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
323 if ( !(xDockWindow.is() && xWindow.is()) )
324 return;
325
326 try
327 {
328 xDockWindow->addDockableWindowListener(
329 css::uno::Reference< css::awt::XDockableWindowListener >(
330 xThis, css::uno::UNO_QUERY ));
331 xWindow->addWindowListener(
332 css::uno::Reference< css::awt::XWindowListener >(
333 xThis, css::uno::UNO_QUERY ));
334 xDockWindow->enableDocking( true );
335 }
336 catch ( const css::uno::Exception& )
337 {
338 }
339}
340
341} // namespace framework
342
343/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
4
Assuming field 'm_pBody' is non-null
5
Taking true branch
113 m_pBody->release();
6
Calling 'VclReferenceBase::release'
10
Returning; memory was released
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
7
Assuming the condition is true
8
Taking true branch
40 delete this;
9
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif