From 1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 19 Jan 2007 01:12:38 +0000 Subject: Every single file in this commit had a memory leak where a resource is allocated in the constructor but not de-allocated in the destructor. This commit fixes that. --- (limited to 'noncore') diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp index 440d8be..28f6318 100644 --- a/noncore/apps/opie-reader/Bkmks.cpp +++ b/noncore/apps/opie-reader/Bkmks.cpp @@ -10,7 +10,12 @@ const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); -Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) +Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : + m_name(0), + m_namelen(0), + m_anno(0), + m_annolen(0), + m_position(0) { init(_nm, _nmlen, _anno, _annolen, _p); } @@ -20,6 +25,17 @@ Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p); } +Bkmk::Bkmk(const Bkmk& rhs) : + m_name(0), + m_namelen(0), + m_anno(0), + m_annolen(0), + m_position(0) +{ + init(rhs.name(), sizeof(tchar)*(ustrlen(rhs.name())+1), rhs.anno(), + sizeof(tchar)*(ustrlen(rhs.anno())+1), rhs.value()); +} + Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) { if (_anno == NULL) diff --git a/noncore/apps/opie-reader/Bkmks.h b/noncore/apps/opie-reader/Bkmks.h index c2275e2..985e158 100644 --- a/noncore/apps/opie-reader/Bkmks.h +++ b/noncore/apps/opie-reader/Bkmks.h @@ -20,15 +20,12 @@ class Bkmk unsigned char m_red,m_green,m_blue, m_level; void init(const void*, unsigned short, const void*, unsigned short, unsigned int); public: - Bkmk() : m_name(NULL), m_namelen(0), m_anno(NULL), m_annolen(0), m_position(0) {}; + Bkmk() : m_name(0), m_namelen(0), m_anno(0), m_annolen(0), m_position(0) {}; Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p); Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short _annolen, unsigned int _p); Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p); Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2); - Bkmk(const Bkmk& rhs) : m_name(NULL), m_anno(NULL) - { - *this = rhs; - } + Bkmk(const Bkmk& rhs); ~Bkmk(); unsigned int value() const { return m_position; } void value(unsigned int _v) { m_position = _v; } diff --git a/noncore/apps/opie-reader/StyleConsts.cpp b/noncore/apps/opie-reader/StyleConsts.cpp index 77c9d3b..c19fa3d 100644 --- a/noncore/apps/opie-reader/StyleConsts.cpp +++ b/noncore/apps/opie-reader/StyleConsts.cpp @@ -4,6 +4,13 @@ GraphicLink::~GraphicLink() { delete graphic; } +pmstore::pmstore(bool _canScale, QImage* p, bool isLnk, unsigned long tgt) : + count(1), + m_isScaleable(_canScale) +{ + graphic = new GraphicLink(p, isLnk, tgt); +} + pmstore::~pmstore() { //// qDebug("Deleting image"); diff --git a/noncore/apps/opie-reader/StyleConsts.h b/noncore/apps/opie-reader/StyleConsts.h index 4b7ff4b..5fd9669 100644 --- a/noncore/apps/opie-reader/StyleConsts.h +++ b/noncore/apps/opie-reader/StyleConsts.h @@ -21,15 +21,13 @@ struct GraphicLink ~GraphicLink(); }; -struct pmstore +class pmstore { + public: unsigned int count; bool m_isScaleable; GraphicLink* graphic; - pmstore(bool _canScale, QImage* p, bool isLnk, unsigned long tgt) : count(1), m_isScaleable(_canScale) - { - graphic = new GraphicLink(p, isLnk, tgt); - } + pmstore(bool _canScale, QImage* p, bool isLnk, unsigned long tgt); ~pmstore(); }; diff --git a/noncore/apps/opie-write/qrichtext.cpp b/noncore/apps/opie-write/qrichtext.cpp index c27eb1e..f040f1e 100644 --- a/noncore/apps/opie-write/qrichtext.cpp +++ b/noncore/apps/opie-write/qrichtext.cpp @@ -6060,7 +6060,7 @@ static QMap *pixmap_map = 0; QTextImage::QTextImage( QTextDocument *p, const QMap &attr, const QString& context, QMimeSourceFactory &factory ) - : QTextCustomItem( p ) + : QTextCustomItem( p ), reg( 0 ) { width = height = 0; if ( attr.contains("width") ) @@ -6068,7 +6068,6 @@ QTextImage::QTextImage( QTextDocument *p, const QMap &attr, co if ( attr.contains("height") ) height = attr["height"].toInt(); - reg = 0; QString imageName = attr["src"]; if (!imageName) @@ -6149,6 +6148,7 @@ QTextImage::QTextImage( QTextDocument *p, const QMap &attr, co QTextImage::~QTextImage() { + delete reg; if ( pixmap_map && pixmap_map->contains( imgId ) ) { QPixmapInt& pmi = pixmap_map->operator[](imgId); pmi.ref--; @@ -6160,7 +6160,6 @@ QTextImage::~QTextImage() } } } - delete reg; } QString QTextImage::richText() const diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.cpp b/noncore/apps/tinykate/libkate/document/katehighlight.cpp index 539d356..89024f7 100644 --- a/noncore/apps/tinykate/libkate/document/katehighlight.cpp +++ b/noncore/apps/tinykate/libkate/document/katehighlight.cpp @@ -389,13 +389,18 @@ const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) } HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) - : HlItem(attribute, context) { + : HlItem(attribute, context), Expr(0) { handlesLinestart=regexp.startsWith("^"); if(!handlesLinestart) regexp.prepend("^"); Expr=new QRegExp3(regexp); } +HlRegExpr::~HlRegExpr() +{ + delete Expr; +} + const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) { if ((!lineStart) && handlesLinestart) return 0; diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.h b/noncore/apps/tinykate/libkate/document/katehighlight.h index fddf585..f0be27b 100644 --- a/noncore/apps/tinykate/libkate/document/katehighlight.h +++ b/noncore/apps/tinykate/libkate/document/katehighlight.h @@ -184,7 +184,7 @@ class HlAnyChar : public HlItem { class HlRegExpr : public HlItem { public: HlRegExpr(int attribute, int context,QString expr); - ~HlRegExpr(){delete Expr;}; + ~HlRegExpr(); virtual const QChar *checkHgl(const QChar *, int len, bool); QRegExp3 *Expr; bool handlesLinestart; -- cgit v0.9.0.2