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

List:       koffice-devel
Subject:    patch for CID 1258
From:       Thomas Zander <zander () kde ! org>
Date:       2006-05-18 12:53:02
Message-ID: 200605181453.04428.zander () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


In libs/kwmf/kwmf.cc there is a design 'error' that an array is used to 
store items in, but the array has a fixed size causing silent (well, it 
_prints_ something) memory leaks when there are more then the predefined 
64 items.  And as we now laugh about some guy ones saying that 640Kb 
would be enough for everyone, I kind of like to fix this correctly. And I 
don't like doing a 'realloc' kind of thing, thats so 1980s.

Here is a patch that converts the array to a QList and it removes all the 
ID based stuff since a QList does that for us.

Comments? Someone with data that can check if this still actually does 
what it is suppost to?

Thanks.
-- 
Thomas Zander

["fixLeaks.diff" (text/x-diff)]

Index: kwmf.cc
===================================================================
--- kwmf.cc	(revision 542142)
+++ kwmf.cc	(working copy)
@@ -34,22 +34,17 @@
 #define PI (3.14159265358979323846)
 
 const int KWmf::s_area = 30504;
-const int KWmf::s_maxHandles = 64;
 
 KWmf::KWmf(
     unsigned dpi)
 {
     m_dpi = dpi;
-    m_objectHandles = new WinObjHandle*[s_maxHandles];
-    memset(m_objectHandles, 0, s_maxHandles * sizeof(WinObjHandle));
 }
 
 KWmf::~KWmf()
 {
-    for(int i = 0; i < s_maxHandles; ++i)
-        handleDelete(i);
-
-    delete[] m_objectHandles;
+    while (!m_objectHandles.isEmpty())
+        delete m_objectHandles.takeFirst();
 }
 
 //
@@ -107,27 +102,11 @@
                static_cast<unsigned int>(stopAngle));
 }
 
-int KWmf::handleIndex(void) const
-{
-    int i;
-
-    for (i = 0; i < s_maxHandles; i++)
-    {
-        if (!m_objectHandles[i])
-            return i;
-    }
-    kError(s_area) << "handle table full !" << endl;
-    return -1;
-}
-
 //-----------------------------------------------------------------------------
 KWmf::WinObjPenHandle *KWmf::handleCreatePen(void)
 {
     WinObjPenHandle *handle = new WinObjPenHandle;
-    int idx = handleIndex();
-
-    Q_ASSERT(idx >= 0);
-    m_objectHandles[idx] = handle;
+    m_objectHandles.append(handle);
     return handle;
 }
 
@@ -135,23 +114,10 @@
 KWmf::WinObjBrushHandle *KWmf::handleCreateBrush(void)
 {
     WinObjBrushHandle *handle = new WinObjBrushHandle;
-    int idx = handleIndex();
-
-    if (idx >= 0)
-        m_objectHandles[idx] = handle;
+    m_objectHandles.append(handle);
     return handle;
 }
 
-//-----------------------------------------------------------------------------
-void KWmf::handleDelete(int idx)
-{
-    if (idx >= 0 && idx < s_maxHandles && m_objectHandles[idx])
-    {
-        delete m_objectHandles[idx];
-        m_objectHandles[idx] = NULL;
-    }
-}
-
 //
 //
 //
@@ -359,9 +325,6 @@
     startedAt = stream.device()->pos();
     stream.setByteOrder(QDataStream::LittleEndian); // Great, I love Qt !
 
-    for (int i = 0; i < s_maxHandles; i++)
-        m_objectHandles[i] = NULL;
-
     typedef struct _RECT
     {
         S16 left;
@@ -688,7 +651,6 @@
     S16 idx;
 
     operands >> idx;
-    handleDelete(idx);
 }
 
 //-----------------------------------------------------------------------------
@@ -699,7 +661,7 @@
     S16 idx;
 
     operands >> idx;
-    if (idx >= 0 && idx < s_maxHandles && m_objectHandles[idx])
+    if (idx >= 0 && idx < m_objectHandles.count())
         m_objectHandles[idx]->apply(*this);
 }
 
Index: kwmf.h
===================================================================
--- kwmf.h	(revision 542142)
+++ kwmf.h	(working copy)
@@ -30,10 +30,12 @@
 #ifndef KWMF_H
 #define KWMF_H
 
-#include <q3valuestack.h>
-//Added by qt3to4:
-#include <QPolygon>
 #include <koffice_export.h>
+
+#include <QList>
+
+#include <q3valuestack.h>
+
 class QDataStream;
 class QPolygon;
 
@@ -143,12 +145,9 @@
         unsigned m_width;
     };
 
-    int handleIndex(void) const;
     WinObjPenHandle *handleCreatePen(void);
     WinObjBrushHandle *handleCreateBrush(void);
-    void handleDelete(int idx);
-    static const int s_maxHandles;
-    WinObjHandle **m_objectHandles;
+    QList<WinObjHandle *>m_objectHandles;
 
     unsigned getColour(S32 colour);
     QPoint normalisePoint(

[Attachment #8 (application/pgp-signature)]

_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


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

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