Kaydet (Commit) cf382b6c authored tarafından Michael Stahl's avatar Michael Stahl

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
üst 96313741
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <rtl/instance.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx> #include <basegfx/matrix/b2dhommatrix.hxx>
#include <hommatrixtemplate.hxx> #include <hommatrixtemplate.hxx>
#include <basegfx/tuple/b2dtuple.hxx> #include <basegfx/tuple/b2dtuple.hxx>
...@@ -32,11 +31,8 @@ namespace basegfx ...@@ -32,11 +31,8 @@ namespace basegfx
{ {
}; };
namespace { struct IdentityMatrix : public rtl::Static< B2DHomMatrix::ImplType, B2DHomMatrix::B2DHomMatrix()
IdentityMatrix > {}; } : mpImpl() // identity
B2DHomMatrix::B2DHomMatrix() :
mpImpl( IdentityMatrix::get() ) // use common identity matrix
{ {
} }
...@@ -55,7 +51,7 @@ namespace basegfx ...@@ -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) 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, 0, f_0x0);
mpImpl->set(0, 1, f_0x1); mpImpl->set(0, 1, f_0x1);
...@@ -104,15 +100,12 @@ namespace basegfx ...@@ -104,15 +100,12 @@ namespace basegfx
bool B2DHomMatrix::isIdentity() const bool B2DHomMatrix::isIdentity() const
{ {
if(mpImpl.same_object(IdentityMatrix::get()))
return true;
return mpImpl->isIdentity(); return mpImpl->isIdentity();
} }
void B2DHomMatrix::identity() void B2DHomMatrix::identity()
{ {
mpImpl = IdentityMatrix::get(); *mpImpl = Impl2DHomMatrix();
} }
bool B2DHomMatrix::isInvertible() const bool B2DHomMatrix::isInvertible() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment