From 0fa0609e1f3bb111805d4940925bc8e744ca1455 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 23 Dec 2006 15:39:26 +0000 Subject: [PATCH] properly delete the regular areas of a RegularArea<> when it stores pointers to areas. no more memory leaks for RegularArea<>, yay! svn path=/trunk/playground/graphics/okular/; revision=616069 --- core/area.h | 34 ++++++++++++++++++++++++++++++++++ core/page.cpp | 8 ++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/core/area.h b/core/area.h index fdd64b3bb..18a11874e 100644 --- a/core/area.h +++ b/core/area.h @@ -272,6 +272,29 @@ struct HighlightRect : public NormalizedRect QColor color; }; + +/** @internal */ +template +class okularDeleter +{ +public: + static void doDelete( T& t ) + { + (void)t; + } +}; + +/** @internal */ +template +class okularDeleter +{ +public: + static void doDelete( T* t ) + { + delete t; + } +}; + /** * @short A regular area of NormalizedShape which normalizes a Shape * @@ -286,6 +309,7 @@ struct HighlightRect : public NormalizedRect template class RegularArea : public QList { public: + ~RegularArea(); bool contains( double x, double y ) const; bool contains( const NormalizedShape& shape ) const; bool intersects (const RegularArea * area) const; @@ -296,6 +320,14 @@ template class RegularArea : public QList< QList* geometry( int xScale, int yScale, int dx=0,int dy=0 ) const; }; +template +RegularArea::~RegularArea() +{ + int size = this->count(); + for ( int i = 0; i < size; ++i ) + okularDeleter::doDelete( (*this)[i] ); +} + template void RegularArea::simplify() { @@ -308,7 +340,9 @@ void RegularArea::simplify() if ( (*this)[x]->intersects( (*this)[i+1] ) ) { *((*this)[x]) |= *((*this)[i+1]); + NormalizedShape tobedeleted = (*this)[i+1]; this->removeAt( i + 1 ); + okularDeleter::doDelete( tobedeleted ); --end; --i; } diff --git a/core/page.cpp b/core/page.cpp index e7cebf7ac..515734bb0 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -582,12 +582,8 @@ void Page::deleteHighlights( int s_id ) void Page::deleteTextSelections() { - if (m_textSelections) - { - qDeleteAll(*m_textSelections); - delete m_textSelections; - m_textSelections = 0; - } + delete m_textSelections; + m_textSelections = 0; } void Page::deleteSourceReferences()