From koffice-devel Thu May 18 12:53:02 2006 From: Thomas Zander Date: Thu, 18 May 2006 12:53:02 +0000 To: koffice-devel Subject: patch for CID 1258 Message-Id: <200605181453.04428.zander () kde ! org> X-MARC-Message: https://marc.info/?l=koffice-devel&m=114795686405575 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============0882626270==" --===============0882626270== Content-Type: multipart/signed; boundary="nextPart20876236.Ogjqb26YMf"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart20876236.Ogjqb26YMf Content-Type: multipart/mixed; boundary="Boundary-01=_w4GbE517C6PAn3v" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_w4GbE517C6PAn3v Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline In libs/kwmf/kwmf.cc there is a design 'error' that an array is used to=20 store items in, but the array has a fixed size causing silent (well, it=20 _prints_ something) memory leaks when there are more then the predefined=20 64 items. And as we now laugh about some guy ones saying that 640Kb=20 would be enough for everyone, I kind of like to fix this correctly. And I=20 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=20 ID based stuff since a QList does that for us. Comments? Someone with data that can check if this still actually does=20 what it is suppost to? Thanks. =2D-=20 Thomas Zander --Boundary-01=_w4GbE517C6PAn3v Content-Type: text/x-diff; charset="us-ascii"; name="fixLeaks.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="fixLeaks.diff" Index: kwmf.cc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kwmf.cc (revision 542142) +++ kwmf.cc (working copy) @@ -34,22 +34,17 @@ #define PI (3.14159265358979323846) =20 const int KWmf::s_area =3D 30504; =2Dconst int KWmf::s_maxHandles =3D 64; =20 KWmf::KWmf( unsigned dpi) { m_dpi =3D dpi; =2D m_objectHandles =3D new WinObjHandle*[s_maxHandles]; =2D memset(m_objectHandles, 0, s_maxHandles * sizeof(WinObjHandle)); } =20 KWmf::~KWmf() { =2D for(int i =3D 0; i < s_maxHandles; ++i) =2D handleDelete(i); =2D =2D delete[] m_objectHandles; + while (!m_objectHandles.isEmpty()) + delete m_objectHandles.takeFirst(); } =20 // @@ -107,27 +102,11 @@ static_cast(stopAngle)); } =20 =2Dint KWmf::handleIndex(void) const =2D{ =2D int i; =2D =2D for (i =3D 0; i < s_maxHandles; i++) =2D { =2D if (!m_objectHandles[i]) =2D return i; =2D } =2D kError(s_area) << "handle table full !" << endl; =2D return -1; =2D} =2D //------------------------------------------------------------------------= =2D---- KWmf::WinObjPenHandle *KWmf::handleCreatePen(void) { WinObjPenHandle *handle =3D new WinObjPenHandle; =2D int idx =3D handleIndex(); =2D =2D Q_ASSERT(idx >=3D 0); =2D m_objectHandles[idx] =3D handle; + m_objectHandles.append(handle); return handle; } =20 @@ -135,23 +114,10 @@ KWmf::WinObjBrushHandle *KWmf::handleCreateBrush(void) { WinObjBrushHandle *handle =3D new WinObjBrushHandle; =2D int idx =3D handleIndex(); =2D =2D if (idx >=3D 0) =2D m_objectHandles[idx] =3D handle; + m_objectHandles.append(handle); return handle; } =20 =2D//----------------------------------------------------------------------= =2D------ =2Dvoid KWmf::handleDelete(int idx) =2D{ =2D if (idx >=3D 0 && idx < s_maxHandles && m_objectHandles[idx]) =2D { =2D delete m_objectHandles[idx]; =2D m_objectHandles[idx] =3D NULL; =2D } =2D} =2D // // // @@ -359,9 +325,6 @@ startedAt =3D stream.device()->pos(); stream.setByteOrder(QDataStream::LittleEndian); // Great, I love Qt ! =20 =2D for (int i =3D 0; i < s_maxHandles; i++) =2D m_objectHandles[i] =3D NULL; =2D typedef struct _RECT { S16 left; @@ -688,7 +651,6 @@ S16 idx; =20 operands >> idx; =2D handleDelete(idx); } =20 //------------------------------------------------------------------------= =2D---- @@ -699,7 +661,7 @@ S16 idx; =20 operands >> idx; =2D if (idx >=3D 0 && idx < s_maxHandles && m_objectHandles[idx]) + if (idx >=3D 0 && idx < m_objectHandles.count()) m_objectHandles[idx]->apply(*this); } =20 Index: kwmf.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kwmf.h (revision 542142) +++ kwmf.h (working copy) @@ -30,10 +30,12 @@ #ifndef KWMF_H #define KWMF_H =20 =2D#include =2D//Added by qt3to4: =2D#include #include + +#include + +#include + class QDataStream; class QPolygon; =20 @@ -143,12 +145,9 @@ unsigned m_width; }; =20 =2D int handleIndex(void) const; WinObjPenHandle *handleCreatePen(void); WinObjBrushHandle *handleCreateBrush(void); =2D void handleDelete(int idx); =2D static const int s_maxHandles; =2D WinObjHandle **m_objectHandles; + QListm_objectHandles; =20 unsigned getColour(S32 colour); QPoint normalisePoint( --Boundary-01=_w4GbE517C6PAn3v-- --nextPart20876236.Ogjqb26YMf Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQBEbG4wCojCW6H2z/QRAhbKAKCObgln6Zebt/LxoJWrgRXj+LLbDQCbB+Vx MCIuZbeqx2txVUqRkSeqsbw= =UtFR -----END PGP SIGNATURE----- --nextPart20876236.Ogjqb26YMf-- --===============0882626270== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ koffice-devel mailing list koffice-devel@kde.org https://mail.kde.org/mailman/listinfo/koffice-devel --===============0882626270==--