[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] filters/sheets/excel: Fix memory leak in sidewinder code by not called destructor on inco
From:       Friedrich W. H. Kossebau <kossebau () kde ! org>
Date:       2013-06-30 21:53:54
Message-ID: E1UtPZC-0007QX-2A () scm ! kde ! org
[Download RAW message or body]

Git commit 4a48f2e57e5948b6662b108bbd71c34043b365e7 by Friedrich W. H. Kossebau.
Committed on 30/06/2013 at 21:52.
Pushed by kossebau into branch 'master'.

Fix memory leak in sidewinder code by not called destructor on incomplete type of \
QTextDocument

REVIEW: 111043

thanks ingwa for review

M  +8    -8    filters/sheets/excel/import/ODrawClient.cpp
M  +70   -17   filters/sheets/excel/sidewinder/excel.cpp
M  +10   -6    filters/sheets/excel/sidewinder/excel.h
M  +1    -1    filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp

http://commits.kde.org/calligra/4a48f2e57e5948b6662b108bbd71c34043b365e7

diff --git a/filters/sheets/excel/import/ODrawClient.cpp \
b/filters/sheets/excel/import/ODrawClient.cpp index c558d73..6db63b9 100644
--- a/filters/sheets/excel/import/ODrawClient.cpp
+++ b/filters/sheets/excel/import/ODrawClient.cpp
@@ -147,7 +147,7 @@ bool ODrawClient::onlyClientData(const MSO::OfficeArtClientData \
&o)  {
     Q_UNUSED(o);
     qDebug() << "NOT YET IMPLEMENTED" << __PRETTY_FUNCTION__;
-    return !m_shapeText.m_text.isEmpty();
+    return !m_shapeText.text().isEmpty();
 }
 
 void ODrawClient::processClientData(const MSO::OfficeArtClientTextBox *ct,
@@ -155,8 +155,8 @@ void ODrawClient::processClientData(const \
MSO::OfficeArtClientTextBox *ct,  {
     Q_UNUSED(ct);
     Q_UNUSED(o);
-    if (m_shapeText.m_doc) { // rich-text
-        KoTextDocument doc(m_shapeText.m_doc);
+    if (m_shapeText.richText()) { // rich-text
+        KoTextDocument doc(m_shapeText.richText());
         Q_ASSERT(!doc.styleManager());
         Q_ASSERT(m_styleManager);
         doc.setStyleManager(m_styleManager);
@@ -164,11 +164,11 @@ void ODrawClient::processClientData(const \
MSO::OfficeArtClientTextBox *ct,  KoEmbeddedDocumentSaver embeddedSaver;
         KoShapeSavingContext context(out.xml, out.styles, embeddedSaver);
         KoTextWriter textWriter(context);
-        textWriter.write(m_shapeText.m_doc.data(), 0);
+        textWriter.write(m_shapeText.richText(), 0);
 
         doc.setStyleManager(0);
     } else { // plain-text
-        QStringList lines = m_shapeText.m_text.split(QRegExp("[\n\r]"));
+        QStringList lines = m_shapeText.text().split(QRegExp("[\n\r]"));
         foreach (const QString& line, lines) {
             out.xml.startElement("text:p", false);
             int pos = 0;
@@ -209,8 +209,8 @@ KoGenStyle ODrawClient::createGraphicStyle(const \
MSO::OfficeArtClientTextBox *ct  Q_UNUSED(cd);
     Q_UNUSED(ds);
     KoGenStyle style = KoGenStyle(KoGenStyle::GraphicAutoStyle, "graphic");
-    if (!m_shapeText.m_text.isEmpty()) {
-        switch (m_shapeText.halign) {
+    if (!m_shapeText.text().isEmpty()) {
+        switch (m_shapeText.hAlign()) {
         case Swinder::TxORecord::Left:
             style.addProperty("draw:textarea-horizontal-align", "left");
             break;
@@ -221,7 +221,7 @@ KoGenStyle ODrawClient::createGraphicStyle(const \
MSO::OfficeArtClientTextBox *ct  style.addProperty("draw:textarea-horizontal-align", \
"right");  break;
         }
-        switch (m_shapeText.valign) {
+        switch (m_shapeText.vAlign()) {
         case Swinder::TxORecord::Top:
             style.addProperty("draw:textarea-vertical-align", "top");
             break;
diff --git a/filters/sheets/excel/sidewinder/excel.cpp \
b/filters/sheets/excel/sidewinder/excel.cpp index 50f54c0..b22ff04 100644
--- a/filters/sheets/excel/sidewinder/excel.cpp
+++ b/filters/sheets/excel/sidewinder/excel.cpp
@@ -1630,23 +1630,58 @@ void ObjRecord::setData(unsigned size, const unsigned char* \
data, const unsigned  
 // ========== TxO ==========
 
+class TxORecord::Private
+{
+public:
+    QString text;
+    QSharedPointer<QTextDocument> richText; // NULL if plainText else it defines the \
richText +
+    TxORecord::HorizontalAlignment hAlign;
+    TxORecord::VerticalAlignment vAlign;
+};
+
+
 const unsigned TxORecord::id = 0x1B6;
 
-TxORecord::TxORecord(Workbook *book) : Record(book) {}
-TxORecord::~TxORecord() {}
+TxORecord::TxORecord(Workbook *book)
+  : Record(book)
+{
+    d = new TxORecord::Private();
+}
+
+TxORecord::TxORecord(const TxORecord& other)
+ : Record(other)
+{
+    d = new TxORecord::Private();
+    operator=(other);
+}
+
+TxORecord::~TxORecord()
+{
+    delete d;
+}
+
+TxORecord& TxORecord::operator=(const TxORecord &other)
+{
+    d->text =     other.d->text;
+    d->richText = other.d->richText;
+    d->hAlign =   other.d->hAlign;
+    d->vAlign =   other.d->vAlign;
+    return *this;
+}
 
 void TxORecord::dump(std::ostream& out) const
 {
     out << "TxO" << std::endl;
-    out << "   " << m_text << " " << halign << " " << valign;
+    out << "   " << d->text << " " << d->hAlign << " " << d->vAlign;
 }
 
 void TxORecord::setData(unsigned size, const unsigned char* data, const unsigned* \
continuePositions)  {
     const unsigned long opts1 = readU16(data);
     //const bool reserved1 = opts1 & 0x01;
-    halign = static_cast<HorizontalAlignment>((opts1 & 0x000e) >> 1); // 3 bits
-    valign = static_cast<VerticalAlignment>((opts1 & 0x0070) >> 4); // 3 bits
+    d->hAlign = static_cast<HorizontalAlignment>((opts1 & 0x000e) >> 1); // 3 bits
+    d->vAlign = static_cast<VerticalAlignment>((opts1 & 0x0070) >> 4); // 3 bits
     //const unsigned long rot = readU16(data + 2);
     // 4 bytes reserved
 
@@ -1676,31 +1711,31 @@ void TxORecord::setData(unsigned size, const unsigned char* \
data, const unsigned  //Q_ASSERT((opts << 1) == 0x0);
 
     // XLUnicodeStringNoCch
-    m_text.clear();
+    d->text.clear();
     unsigned k = 1;
     if(fHighByte) {
         for (; startPict + k + 1 < endPict; k += 2) {
             unsigned zc = readU16(startPict + k);
             if (!zc) break;
             if (!QChar(zc).isPrint() && zc != 10) {
-                m_text.clear();
+                d->text.clear();
                 break;
             }
-            m_text.append(QChar(zc));
+            d->text.append(QChar(zc));
         }
     } else {
         for (; startPict + k < endPict; k += 1) {
             unsigned char uc = readU8(startPict + k) + 0x0*256;
             if (!uc) break;
             if (!QChar(uc).isPrint() && uc != 10) {
-                m_text.clear();
+                d->text.clear();
                 break;
             }
-            m_text.append(QChar(uc));
+            d->text.append(QChar(uc));
         }
     }
 
-    m_doc.clear();
+    d->richText.clear();
 
     // Now look for TxORun structures that specify the formatting run information \
for the TxO record.  int ToXRunsPositionIndex = 0;
@@ -1716,11 +1751,11 @@ void TxORecord::setData(unsigned size, const unsigned char* \
data, const unsigned  ++ToXRunsPositionIndex;
     } while(true);
     if (ToXRunsPositionIndex > 0) {
-        m_doc = QSharedPointer<QTextDocument>(new QTextDocument());
+        d->richText = QSharedPointer<QTextDocument>(new QTextDocument());
         // also add a textrangemanager, as KoTextWriter assumes one
-        KoTextDocument(m_doc).setTextRangeManager(new KoTextRangeManager);
-        m_doc->setPlainText(m_text);
-        QTextCursor cursor(m_doc.data());
+        KoTextDocument(d->richText).setTextRangeManager(new KoTextRangeManager);
+        d->richText->setPlainText(d->text);
+        QTextCursor cursor(d->richText.data());
         //cursor.setVisualNavigation(true);
         QTextCharFormat format;
         unsigned pos = continuePositions[ToXRunsPositionIndex];
@@ -1734,7 +1769,7 @@ void TxORecord::setData(unsigned size, const unsigned char* \
data, const unsigned  cursor.setPosition(ich, QTextCursor::MoveAnchor);
             }
 
-            if (ich >= unsigned(m_text.length())) {
+            if (ich >= unsigned(d->text.length())) {
                 break;
             }
 
@@ -1752,8 +1787,26 @@ void TxORecord::setData(unsigned size, const unsigned char* \
data, const unsigned  }
     }
 
-    std::cout << "TxORecord::setData size=" << size << " text=" << \
qPrintable(m_text) << std::endl; +    std::cout << "TxORecord::setData size=" << size \
<< " text=" << qPrintable(d->text) << std::endl; +}
+
+const QString& TxORecord::text() const
+{
+    return d->text;
 }
+TxORecord::HorizontalAlignment TxORecord::hAlign() const
+{
+    return d->hAlign;
+}
+TxORecord::VerticalAlignment TxORecord::vAlign() const
+{
+    return d->vAlign;
+}
+const QTextDocument* TxORecord::richText() const
+{
+    return d->richText.data();
+}
+
 
 // ========== MsoDrawing ==========
 
diff --git a/filters/sheets/excel/sidewinder/excel.h \
b/filters/sheets/excel/sidewinder/excel.h index 5b0076c..47f2d54 100644
--- a/filters/sheets/excel/sidewinder/excel.h
+++ b/filters/sheets/excel/sidewinder/excel.h
@@ -796,15 +796,12 @@ public:
         VDistributed = 7
     };
 
-    QString m_text;
-    QSharedPointer<QTextDocument> m_doc; // NULL if plainText else it defines the \
                richText
-
-    HorizontalAlignment halign;
-    VerticalAlignment valign;
-
     static const unsigned id;
     explicit TxORecord(Workbook *book=0);
+    // allowing copies for the hack for text support in shapes
+    TxORecord(const TxORecord&);
     virtual ~TxORecord();
+    TxORecord& operator=(const TxORecord&);
     virtual unsigned rtti() const {
         return this->id;
     }
@@ -813,6 +810,13 @@ public:
     }
     virtual void dump(std::ostream&) const;
     virtual void setData(unsigned size, const unsigned char* data, const unsigned* \
continuePositions); +    const QString &text() const;
+    TxORecord::HorizontalAlignment hAlign() const;
+    TxORecord::VerticalAlignment vAlign() const;
+    const QTextDocument *richText() const;
+private:
+    class Private;
+    Private *d;
 };
 
 class MsoDrawingRecord : public Record
diff --git a/filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp \
b/filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp index \
                bd66048..383bd0d 100644
--- a/filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp
+++ b/filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp
@@ -738,7 +738,7 @@ void WorksheetSubStreamHandler::handleTxO(TxORecord* record)
     if (d->sharedObjects.rbegin() != d->sharedObjects.rend()) {
         NoteObject* no = \
dynamic_cast<NoteObject*>(d->sharedObjects.rbegin()->second);  if (no) {
-            no->setNote(record->m_text);
+            no->setNote(record->text());
         }
     }
     if (d->lastOfficeArtObject) {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic