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

List:       koffice-devel
Subject:    [PATCH] Memory leak in KoPicture
From:       Nicolas Goutte <nicog () snafu ! de>
Date:       2002-07-26 19:58:49
[Download RAW message or body]

I have found a bug in KoPicture / KoPictureShared that leads to a (big) memory 
leak. If possible, I would like to commit this patch for KOffice 1.2 RC1.

That patch is for the directory lib/kofficecore

The problem is in QShared (initialized with 1 instead of 0), so I do without. 
(I will bug Trolltech later.)

As the QShared bug also hit QImage (with its calls QImageData) part of the 
problems seen with KPresenter could be from this origin.

Have a nice day/evening/night!




["patch.txt" (text/plain)]

Index: koPicture.cc
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koPicture.cc,v
retrieving revision 1.14
diff -u -r1.14 koPicture.cc
--- koPicture.cc	2002/06/22 20:03:59	1.14
+++ koPicture.cc	2002/07/26 19:51:22
@@ -59,8 +59,12 @@
 
 void KoPicture::unlinkSharedData(void)
 {
-    if (m_sharedData && m_sharedData->deref())
-        delete m_sharedData;
+    if (m_sharedData)
+    {
+        m_sharedData->m_shareCount--;
+        if (!m_sharedData->m_shareCount)
+            delete m_sharedData;
+    }
 
     m_sharedData=NULL;
 }
@@ -68,7 +72,7 @@
 void KoPicture::linkSharedData(void) const
 {
     if (m_sharedData)
-        m_sharedData->ref();
+        m_sharedData->m_shareCount++;
 }
 
 void KoPicture::createSharedData(void)
Index: koPictureShared.cc
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koPictureShared.cc,v
retrieving revision 1.12
diff -u -r1.12 koPictureShared.cc
--- koPictureShared.cc	2002/07/12 21:09:28	1.12
+++ koPictureShared.cc	2002/07/26 19:51:23
@@ -30,7 +30,7 @@
 #include "koPictureClipart.h"
 #include "koPictureShared.h"
 
-KoPictureShared::KoPictureShared(void) : m_base(NULL)
+KoPictureShared::KoPictureShared(void) : m_shareCount(0), m_base(NULL)
 {
 }
 
@@ -41,7 +41,6 @@
 }
 
 KoPictureShared::KoPictureShared(const KoPictureShared &other)
-    : QShared() // Some compilers want it explicitely!
 {
     // We need to use newCopy, because we want a real copy, not just a copy of the part of KoPictureBase
     if (other.m_base)
Index: koPictureShared.h
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koPictureShared.h,v
retrieving revision 1.10
diff -u -r1.10 koPictureShared.h
--- koPictureShared.h	2002/07/12 21:09:28	1.10
+++ koPictureShared.h	2002/07/26 19:51:23
@@ -36,9 +36,9 @@
  * @internal
  * KoPictureShared is the class that contains the shared part for KoPicture
  *
- * As with all QShared objects, the sharing is neither automatic nor transparent!
+ * Be careful the sharing is neither automatic nor transparent!
  */
-class KoPictureShared : public QShared
+class KoPictureShared
 {
 public:
     /**
@@ -154,13 +154,18 @@
      * Load a WMF file (a .wmf file could be a QPicture file)
      */
     bool loadWmf(QIODevice* io);
-    
+
     /**
      * @internal
      * Loads a temporary file, probably from a downloaded file
      */
     bool loadTmp(QIODevice* io);
 
+public:
+    /**
+     * How many times this object is shared
+     */
+    uint m_shareCount;
 protected:
     KoPictureBase* m_base;
     QString m_extension;

_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://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