Blame SOURCES/0003-rhbz-1205072-sw-resource-mangement-SNAFU-caused-by-S.patch

ebc4bd
From 2b23c9c3d39667a740b8dc83326875d84454ab93 Mon Sep 17 00:00:00 2001
ebc4bd
From: Michael Stahl <mstahl@redhat.com>
ebc4bd
Date: Sat, 25 Apr 2015 21:25:00 +0200
ebc4bd
Subject: [PATCH 3/4] rhbz#1205072: sw: resource mangement SNAFU caused by
ebc4bd
 SwPaM copy ctor
ebc4bd
ebc4bd
SwPaM copy ctor has the surprising habit of linking the new one into the
ebc4bd
old one's Ring.  If you copy a shell cursor, *this* epic fail happens:
ebc4bd
ebc4bd
==948== Thread 6 SelectionManager:
ebc4bd
==948== Invalid free() / delete / delete[] / realloc()
ebc4bd
==948==    at 0x4A07CE9: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
ebc4bd
==948==    by 0x222F542B: SwPaM::operator delete(void*, unsigned long) (in /libreoffice-4-3/instdir/program/libswlo.so)
ebc4bd
==948==    by 0x2239E20E: SwPaM::~SwPaM() (pam.cxx:422)
ebc4bd
==948==    by 0x22368630: CheckRange(SwCursor*) (crsrsh.cxx:111)
ebc4bd
==948==    by 0x2236DECC: SwCrsrShell::UpdateCrsr(unsigned short, bool) (crsrsh.cxx:1397)
ebc4bd
==948==    by 0x22369113: SwCrsrShell::EndAction(bool) (crsrsh.cxx:290)
ebc4bd
==948==    by 0x2268971F: SwEditShell::EndAllAction() (edws.cxx:87)
ebc4bd
==948==    by 0x2262BEF3: SwBaseLink::DataChanged(rtl::OUString const&, com::sun::star::uno::Any const&) (swbaslnk.cxx:274)
ebc4bd
==948==    by 0x2262C78E: SwBaseLink::SwapIn(bool, bool) (swbaslnk.cxx:411)
ebc4bd
==948==    by 0x227102EC: SwGrfNode::SwapIn(bool) (ndgrf.cxx:539)
ebc4bd
==948==    by 0x227121BC: SwGrfNode::MakeCopy(SwDoc*, SwNodeIndex const&) const (ndgrf.cxx:999)
ebc4bd
==948==    by 0x22610E4D: SwNodes::_CopyNodes(SwNodeRange const&, SwNodeIndex const&, bool, bool) const (nodes.cxx:1862)
ebc4bd
==948==    by 0x225B98E0: SwDoc::CopyWithFlyInFly(SwNodeRange const&, int, SwNodeIndex const&, SwPaM const*, bool, bool, bool) const (ndcopy.cxx:1336)
ebc4bd
==948==    by 0x224AC1FF: SwDoc::CopyLayoutFmt(SwFrmFmt const&, SwFmtAnchor const&, bool, bool) (doclay.cxx:446)
ebc4bd
==948==    by 0x2294D2D4: SwTxtFlyCnt::CopyFlyFmt(SwDoc*) (atrflyin.cxx:130)
ebc4bd
==948==    by 0x229A5B96: MakeTxtAttr(SwDoc&, SfxPoolItem&, int, int, CopyOrNew_t, SwTxtNode*) (thints.cxx:1060)
ebc4bd
==948==    by 0x229A64E6: SwTxtNode::InsertItem(SfxPoolItem&, int, int, unsigned short) (thints.cxx:1224)
ebc4bd
==948==    by 0x2298E536: SwTxtNode::CopyText(SwTxtNode*, SwIndex const&, SwIndex const&, int, bool) (ndtxt.cxx:1773)
ebc4bd
==948==    by 0x2298DC08: SwTxtNode::CopyText(SwTxtNode*, SwIndex const&, int, bool) (ndtxt.cxx:1555)
ebc4bd
==948==    by 0x225B4C9D: SwTxtNode::MakeCopy(SwDoc*, SwNodeIndex const&) const (ndcopy.cxx:286)
ebc4bd
==948==    by 0x22610E4D: SwNodes::_CopyNodes(SwNodeRange const&, SwNodeIndex const&, bool, bool) const (nodes.cxx:1862)
ebc4bd
==948==    by 0x223EF3C2: SwNodes::_Copy(SwNodeRange const&, SwNodeIndex const&, bool) const (ndarr.hxx:182)
ebc4bd
==948==    by 0x225B5D8D: SwTableNode::MakeCopy(SwDoc*, SwNodeIndex const&) const (ndcopy.cxx:475)
ebc4bd
==948==    by 0x22610ACA: SwNodes::_CopyNodes(SwNodeRange const&, SwNodeIndex const&, bool, bool) const (nodes.cxx:1790)
ebc4bd
==948==    by 0x223EF3C2: SwNodes::_Copy(SwNodeRange const&, SwNodeIndex const&, bool) const (ndarr.hxx:182)
ebc4bd
==948==    by 0x225CA663: SwSectionNode::MakeCopy(SwDoc*, SwNodeIndex const&) const (ndsect.cxx:1270)
ebc4bd
==948==    by 0x22610BFC: SwNodes::_CopyNodes(SwNodeRange const&, SwNodeIndex const&, bool, bool) const (nodes.cxx:1817)
ebc4bd
==948==    by 0x223EF3C2: SwNodes::_Copy(SwNodeRange const&, SwNodeIndex const&, bool) const (ndarr.hxx:182)
ebc4bd
==948==    by 0x225CA663: SwSectionNode::MakeCopy(SwDoc*, SwNodeIndex const&) const (ndsect.cxx:1270)
ebc4bd
==948==    by 0x22610BFC: SwNodes::_CopyNodes(SwNodeRange const&, SwNodeIndex const&, bool, bool) const (nodes.cxx:1817)
ebc4bd
==948==    by 0x223EF3C2: SwNodes::_Copy(SwNodeRange const&, SwNodeIndex const&, bool) const (ndarr.hxx:182)
ebc4bd
==948==    by 0x225CA663: SwSectionNode::MakeCopy(SwDoc*, SwNodeIndex const&) const (ndsect.cxx:1270)
ebc4bd
==948==    by 0x22610BFC: SwNodes::_CopyNodes(SwNodeRange const&, SwNodeIndex const&, bool, bool) const (nodes.cxx:1817)
ebc4bd
==948==    by 0x225B98E0: SwDoc::CopyWithFlyInFly(SwNodeRange const&, int, SwNodeIndex const&, SwPaM const*, bool, bool, bool) const (ndcopy.cxx:1336)
ebc4bd
==948==    by 0x225B8F15: SwDoc::CopyImpl(SwPaM&, SwPosition&, bool, bool, SwPaM*) const (ndcopy.cxx:1239)
ebc4bd
==948==    by 0x225B6EE0: SwDoc::CopyRange(SwPaM&, SwPosition&, bool) const (ndcopy.cxx:707)
ebc4bd
==948==    by 0x22667E69: SwEditShell::_CopySelToDoc(SwDoc*, SwNodeIndex*) (edglss.cxx:244)
ebc4bd
==948==    by 0x226C8400: SwFEShell::Copy(SwDoc*, rtl::OUString const*) (fecopy.cxx:214)
ebc4bd
==948==    by 0x22DBF72B: (anonymous namespace)::lclOverWriteDoc(SwWrtShell&, SwDoc&) (swdtflvr.cxx:373)
ebc4bd
==948==    by 0x22DBFBC6: SwTransferable::GetData(com::sun::star::datatransfer::DataFlavor const&, rtl::OUString const&) (swdtflvr.cxx:439)
ebc4bd
==948==    by 0x7CB36C7: TransferableHelper::getTransferData2(com::sun::star::datatransfer::DataFlavor const&, rtl::OUString const&) (transfer.cxx:332)
ebc4bd
==948==    by 0x7CB34B5: TransferableHelper::getTransferData(com::sun::star::datatransfer::DataFlavor const&) (transfer.cxx:306)
ebc4bd
==948==    by 0x17A7E949: x11::SelectionManager::convertData(com::sun::star::uno::Reference<com::sun::star::datatransfer::XTransferable> const&, unsigned long, unsigned long, int&, com::sun::star::uno::Sequence<signed char>&) (X11_selection.cxx:655)
ebc4bd
==948==    by 0x17A823CA: x11::SelectionManager::sendData(x11::SelectionAdaptor*, unsigned long, unsigned long, unsigned long, unsigned long) (X11_selection.cxx:1503)
ebc4bd
==948==    by 0x17A82E03: x11::SelectionManager::handleSelectionRequest(XSelectionRequestEvent&) (X11_selection.cxx:1729)
ebc4bd
==948==    by 0x17A8A08A: x11::SelectionManager::handleXEvent(_XEvent&) (X11_selection.cxx:3574)
ebc4bd
==948==  Address 0x21e31a60 is on thread 6's stack
ebc4bd
==948==  in frame #40, created by SwEditShell::_CopySelToDoc(SwDoc*, SwNodeIndex*) (edglss.cxx:158)
ebc4bd
ebc4bd
(regression from 49505336a629a75f4fb48bbe0c532b402e857ed4)
ebc4bd
ebc4bd
(cherry picked from commit c55599fd0e7198773087c6433031f7119aaaca36)
ebc4bd
ebc4bd
Conflicts:
ebc4bd
	sw/source/core/edit/edglss.cxx
ebc4bd
ebc4bd
Reviewed-on: https://gerrit.libreoffice.org/15533
ebc4bd
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
ebc4bd
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
ebc4bd
(cherry picked from commit 8f570028b0871dbaaaa99722cca76c0d1179e06c)
ebc4bd
ebc4bd
Conflicts:
ebc4bd
	sw/source/core/edit/edglss.cxx
ebc4bd
ebc4bd
Change-Id: I3d0a288a83b4719dda7977b4898dea656ea67388
ebc4bd
---
ebc4bd
 sw/source/core/edit/eddel.cxx  | 2 +-
ebc4bd
 sw/source/core/edit/edglss.cxx | 5 ++++-
ebc4bd
 2 files changed, 5 insertions(+), 2 deletions(-)
ebc4bd
ebc4bd
diff --git a/sw/source/core/edit/eddel.cxx b/sw/source/core/edit/eddel.cxx
ebc4bd
index 9e2c7b2..c5ed1e9 100644
ebc4bd
--- a/sw/source/core/edit/eddel.cxx
ebc4bd
+++ b/sw/source/core/edit/eddel.cxx
ebc4bd
@@ -94,7 +94,7 @@ void SwEditShell::DeleteSel( SwPaM& rPam, bool* pUndo )
ebc4bd
         if (bSelectAll)
ebc4bd
         {
ebc4bd
             assert(dynamic_cast<SwShellCrsr*>(&rPam)); // must be corrected pam
ebc4bd
-            pNewPam.reset(new SwPaM(rPam));
ebc4bd
+            pNewPam.reset(new SwPaM(*rPam.GetMark(), *rPam.GetPoint()));
ebc4bd
             // Selection starts at the first para of the first cell, but we
ebc4bd
             // want to delete the table node before the first cell as well.
ebc4bd
             pNewPam->Start()->nNode = pNewPam->Start()->nNode.GetNode().FindTableNode()->GetIndex();
ebc4bd
diff --git a/sw/source/core/edit/edglss.cxx b/sw/source/core/edit/edglss.cxx
ebc4bd
index 7a17737..084c221 100644
ebc4bd
--- a/sw/source/core/edit/edglss.cxx
ebc4bd
+++ b/sw/source/core/edit/edglss.cxx
ebc4bd
@@ -235,12 +235,15 @@ bool SwEditShell::_CopySelToDoc( SwDoc* pInsDoc, SwNodeIndex* pSttNd )
ebc4bd
                 // Make a copy, so that in case we need to adjust the selection
ebc4bd
                 // for the purpose of copying, our shell cursor is not touched.
ebc4bd
                 // (Otherwise we would have to restore it.)
ebc4bd
-                SwPaM aPaM(*PCURCRSR);
ebc4bd
+                SwPaM aPaM(*PCURCRSR->GetMark(), *PCURCRSR->GetPoint());
ebc4bd
                 if (bSelectAll)
ebc4bd
+                {
ebc4bd
                     // Selection starts at the first para of the first cell,
ebc4bd
                     // but we want to copy the table and the start node before
ebc4bd
                     // the first cell as well.
ebc4bd
                     aPaM.Start()->nNode = aPaM.Start()->nNode.GetNode().FindTableNode()->GetIndex();
ebc4bd
+                    aPaM.Start()->nContent.Assign(nullptr, 0);
ebc4bd
+                }
ebc4bd
                 bRet = GetDoc()->CopyRange( aPaM, aPos, false ) || bRet;
ebc4bd
             }
ebc4bd
 
ebc4bd
-- 
ebc4bd
2.1.0
ebc4bd