summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-06-10 11:08:36 +0200
committerAndras Timar <andras.timar@collabora.com>2020-06-11 09:21:16 +0200
commit35677f1d11ff26fda86ddc9d6d73c3ee2b52fe2b (patch)
tree26df001ab6cd0efaade75568ece6dd5f798d416d /include
parent3ebb1523608959137b2a877b9db06edac653d3a7 (diff)
fix reseting WeakReference when moving a ref to another ref.
In ViewIteratorImpl::Reverse we std::move a reference, to a local variable, however the reference was not reset correctly, which caused a crash. The issue is that a mpWeakConnection in WeakReference always needs to be non-null as shown in reset(reference_type* pReference) method. In the move constructor of WeakReference, we just std::move the reference like: mpWeakConnection = std::move(rWeakRef.mpWeakConnection); This means rWeakRef.mpWeakConnection will be reset to null, which is not what is expected, so what is missing is to instantiate rWeakRef.mpWeakConnection by calling reset(nullptr) or using the added reset() method. This also adds a test for LOKit PDF search as this is the case where the crash has been reproduced. It happens because of a call to: ... std::move(maPosition.mxObject); in the method ViewIteratorImpl::Reverse() Change-Id: I43692554ba4f6231d00091269b7c902ab5cbc11f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95995 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 8ca89dc44aa5905d8d189be765ad2a1a613d31f4) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96070 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'include')
-rw-r--r--include/tools/weakbase.h5
-rw-r--r--include/tools/weakbase.hxx9
2 files changed, 12 insertions, 2 deletions
diff --git a/include/tools/weakbase.h b/include/tools/weakbase.h
index 458381e47fff..fbd49d2ecf90 100644
--- a/include/tools/weakbase.h
+++ b/include/tools/weakbase.h
@@ -82,7 +82,7 @@ public:
/** constructs a reference from another reference */
inline WeakReference( const WeakReference< reference_type >& rWeakRef );
- /** constructs a reference from another reference */
+ /** move a reference from another reference */
inline WeakReference( WeakReference< reference_type >&& rWeakRef );
/** returns true if the reference object is not null and still alive */
@@ -94,6 +94,9 @@ public:
/** sets this reference to the given object or null */
inline void reset( reference_type* pReference );
+ /** resets this reference to null */
+ inline void reset();
+
/** returns the pointer to the reference object or null */
inline reference_type * operator->() const;
diff --git a/include/tools/weakbase.hxx b/include/tools/weakbase.hxx
index fa16edd2f147..8bc4611abb0c 100644
--- a/include/tools/weakbase.hxx
+++ b/include/tools/weakbase.hxx
@@ -49,6 +49,7 @@ template< class reference_type >
inline WeakReference< reference_type >::WeakReference( WeakReference< reference_type >&& rWeakRef )
{
mpWeakConnection = std::move(rWeakRef.mpWeakConnection);
+ rWeakRef.reset();
}
template< class reference_type >
@@ -73,7 +74,13 @@ inline void WeakReference< reference_type >::reset( reference_type* pReference )
if( pReference )
mpWeakConnection = pReference->getWeakConnection();
else
- mpWeakConnection = new WeakConnection;
+ reset();
+}
+
+template< class reference_type >
+inline void WeakReference< reference_type >::reset()
+{
+ mpWeakConnection = new WeakConnection;
}
template< class reference_type >