diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-06-10 11:08:36 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-06-10 15:58:16 +0200 |
commit | 8ca89dc44aa5905d8d189be765ad2a1a613d31f4 (patch) | |
tree | 00c40ccf3e3e8d89ee1cb21d4e7071acae33ef78 /include/tools/weakbase.hxx | |
parent | 2a82ea5c04f76af330686cd31e68f6f0d628db74 (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>
Diffstat (limited to 'include/tools/weakbase.hxx')
-rw-r--r-- | include/tools/weakbase.hxx | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/tools/weakbase.hxx b/include/tools/weakbase.hxx index 5c1645e69cf1..ca6bdc37e6d4 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 > |