basegfx/source/matrix/b2dhommatrix.cxx |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

New commits:
commit cf382b6c0ea509d90855f348097dc0075671055d
Author: Michael Stahl <mst...@redhat.com>
Date:   Wed May 31 16:15:52 2017 +0200

    basegfx: remove global IdentityMatrix thread safety hazard
    
    ASAN reports this about JunitTest_chart2_unoapi
    
    ==27381==ERROR: AddressSanitizer: heap-use-after-free on address 
0x6060005bd218 at pc 0x7ff229755271 bp 0x7fffb52c6c30 sp 0x7fffb52c6c28
    READ of size 8 at 0x6060005bd218 thread T0
        #0 0x7ff229755270 in 
o3tl::UnsafeRefCountingPolicy::decrementCount(unsigned long&) 
include/o3tl/cow_wrapper.hxx:41:68
        #1 0x7ff2297551bf in o3tl::cow_wrapper<basegfx::Impl2DHomMatrix, 
o3tl::UnsafeRefCountingPolicy>::release() include/o3tl/cow_wrapper.hxx:203:29
        #2 0x7ff2297515f0 in o3tl::cow_wrapper<basegfx::Impl2DHomMatrix, 
o3tl::UnsafeRefCountingPolicy>::~cow_wrapper() 
include/o3tl/cow_wrapper.hxx:248:13
        #3 0x7ff242ef440f in __run_exit_handlers (/lib64/libc.so.6+0x3a40f)
        #4 0x7ff242ef4469 in __GI_exit (/lib64/libc.so.6+0x3a469)
    
    The reason appears to be the UnsafeRefCountingPolicy on the global
    IdentityMatrix, so every B2DHomMatrix that is created on any thread
    will manipulate the refcount of that global without synchronisation.
    
    Let's just remove the global and hope the extra allocations don't matter.
    
    Change-Id: I4962ab2e622286f29b912a57448f3f1a53eeb592

diff --git a/basegfx/source/matrix/b2dhommatrix.cxx 
b/basegfx/source/matrix/b2dhommatrix.cxx
index b852a013a20a..f9bc24e81ea4 100644
--- a/basegfx/source/matrix/b2dhommatrix.cxx
+++ b/basegfx/source/matrix/b2dhommatrix.cxx
@@ -17,7 +17,6 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <rtl/instance.hxx>
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <hommatrixtemplate.hxx>
 #include <basegfx/tuple/b2dtuple.hxx>
@@ -32,11 +31,8 @@ namespace basegfx
     {
     };
 
-    namespace { struct IdentityMatrix : public rtl::Static< 
B2DHomMatrix::ImplType,
-                                                            IdentityMatrix > 
{}; }
-
-    B2DHomMatrix::B2DHomMatrix() :
-        mpImpl( IdentityMatrix::get() ) // use common identity matrix
+    B2DHomMatrix::B2DHomMatrix()
+        : mpImpl() // identity
     {
     }
 
@@ -55,7 +51,7 @@ namespace basegfx
     }
 
     B2DHomMatrix::B2DHomMatrix(double f_0x0, double f_0x1, double f_0x2, 
double f_1x0, double f_1x1, double f_1x2)
-    :   mpImpl( IdentityMatrix::get() ) // use common identity matrix, will be 
made unique with 1st set-call
+        :   mpImpl() // identity
     {
         mpImpl->set(0, 0, f_0x0);
         mpImpl->set(0, 1, f_0x1);
@@ -104,15 +100,12 @@ namespace basegfx
 
     bool B2DHomMatrix::isIdentity() const
     {
-        if(mpImpl.same_object(IdentityMatrix::get()))
-            return true;
-
         return mpImpl->isIdentity();
     }
 
     void B2DHomMatrix::identity()
     {
-        mpImpl = IdentityMatrix::get();
+        *mpImpl = Impl2DHomMatrix();
     }
 
     bool B2DHomMatrix::isInvertible() const
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to