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

List:       kde-core-devel
Subject:    KControl leak and changes in some kcm modules
From:       Albert Astals Cid <astals11 () terra ! es>
Date:       2004-01-20 22:24:47
Message-ID: 200401202323.43439.astals11 () terra ! es
[Download RAW message or body]

Hi, today i discovered some memory leakage in kcontrol toplevel.cpp, it was 
calling aboutData that returns a pointer to a KAboutData but never deleting 
it. I tried to fix it, but then realized that some kcm modules don't return a 
new KAboutData pointer each time. Some return a class member and some have a 
static variable, but the most return a new KAboutData each time, so i have 
looked at the CVS and chagned the few that didn't return a new KAboutData 
each time to do so. Here come the patches.

Can you please review them and tell me if i can commit them.



["kcontrolPatchkcontrol" (text/x-diff)]

? kcontrolPatchkcontrol
Index: email/email.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/email/email.cpp,v
retrieving revision 1.87
diff -u -r1.87 email.cpp
--- email/email.cpp	8 Nov 2003 23:43:50 -0000	1.87
+++ email/email.cpp	20 Jan 2004 22:04:34 -0000
@@ -84,13 +84,30 @@
 	m_email->btnNewProfile->hide();
 	load();
 
-	mAboutData = new KAboutData("kcmemail", I18N_NOOP("KDE Email Control Module"), \
"1.0", +	if ( m_email->txtFullName->text().isEmpty() &&
+	     m_email->txtOrganization->text().isEmpty() &&
+	     m_email->txtEMailAddr->text().isEmpty() &&
+	     m_email->txtReplyTo->text().isEmpty() &&
+	     m_email->txtSMTP->text().isEmpty() )
+	{
+		KConfigGroup config( EMailFactory::instance()->config(),
+				     "General" );
+		if ( config.readBoolEntry( "FirstStart", true ) )
+			defaults();
+	}
+
+	m_email->txtFullName->setFocus();
+}
+
+const KAboutData * topKCMEmail::aboutData() const
+{
+	KAboutData *aboutData = new KAboutData("kcmemail", I18N_NOOP("KDE Email Control \
Module"), "1.0",  I18N_NOOP("Configure your identity, email addresses, mail servers, \
etc."),  KAboutData::License_Custom);
-	mAboutData->addAuthor("Michael H\303\244ckel", I18N_NOOP("Current maintainer"), \
                "haeckel@kde.org" );
-	mAboutData->addAuthor("Daniel Molkentin");
-	mAboutData->addAuthor("Alex Zepeda");
-	mAboutData->setLicenseText(
+	aboutData->addAuthor("Michael H\303\244ckel", I18N_NOOP("Current maintainer"), \
"haeckel@kde.org" ); +	aboutData->addAuthor("Daniel Molkentin");
+	aboutData->addAuthor("Alex Zepeda");
+	aboutData->setLicenseText(
 	"You can freely distribute this program under the following terms:\n"
 	"\n"
 	"1.) If you use this program in a product outside of KDE, you must\n"
@@ -114,29 +131,7 @@
 	"OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"
 	"SUCH DAMAGE.");
 
-	if ( m_email->txtFullName->text().isEmpty() &&
-	     m_email->txtOrganization->text().isEmpty() &&
-	     m_email->txtEMailAddr->text().isEmpty() &&
-	     m_email->txtReplyTo->text().isEmpty() &&
-	     m_email->txtSMTP->text().isEmpty() )
-	{
-		KConfigGroup config( EMailFactory::instance()->config(),
-				     "General" );
-		if ( config.readBoolEntry( "FirstStart", true ) )
-			defaults();
-	}
-
-	m_email->txtFullName->setFocus();
-}
-
-topKCMEmail::~topKCMEmail()
-{
-	delete mAboutData;
-}
-
-const KAboutData * topKCMEmail::aboutData() const
-{
-	return mAboutData;
+	return aboutData;
 }
 
 void topKCMEmail::load()
Index: email/email.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/email/email.h,v
retrieving revision 1.27
diff -u -r1.27 email.h
--- email/email.h	27 Jul 2002 18:51:31 -0000	1.27
+++ email/email.h	20 Jan 2004 22:04:35 -0000
@@ -60,7 +60,6 @@
 
 public:
 	topKCMEmail (QWidget *parent = 0, const char *name = 0, const QStringList &list \
                =QStringList() );
-	~topKCMEmail ();
 	virtual const KAboutData * aboutData () const;
 
 	KCMEmailBase *m_email;
@@ -85,7 +84,6 @@
 
 protected:
 	void clearData();
-	KAboutData *mAboutData;
 	KEMailSettings *pSettings;
 	QString m_sICMPassword, m_sICMUsername, m_sICMPath, m_sICMHost;
 	QString m_sOGMPassword, m_sOGMUsername, m_sOGMCommand, m_sOGMHost;
Index: icons/main.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/icons/main.cpp,v
retrieving revision 1.20
diff -u -r1.20 main.cpp
--- icons/main.cpp	8 Nov 2003 23:43:51 -0000	1.20
+++ icons/main.cpp	20 Jan 2004 22:04:35 -0000
@@ -94,18 +94,13 @@
 
 const KAboutData *IconModule::aboutData() const
 {
-    static KAboutData* ab = 0;
-
-    if (!ab)
-    {
-        ab = new KAboutData("kcmicons", I18N_NOOP("Icons"), "3.0",
+    KAboutData* ab = new KAboutData("kcmicons", I18N_NOOP("Icons"), "3.0",
                             I18N_NOOP("Icons Control Panel Module"),
                             KAboutData::License_GPL,
                             I18N_NOOP("(c) 2000-2003 Geert Jansen"), 0, 0);
-        ab->addAuthor("Geert Jansen", 0, "jansen@kde.org");
-        ab->addAuthor("Antonio Larrosa Jimenez", 0, "larrosa@kde.org");
-        ab->addCredit("Torsten Rahn", 0, "torsten@kde.org");
-    }
+    ab->addAuthor("Geert Jansen", 0, "jansen@kde.org");
+    ab->addAuthor("Antonio Larrosa Jimenez", 0, "larrosa@kde.org");
+    ab->addCredit("Torsten Rahn", 0, "torsten@kde.org");
 
     return ab;
 }
Index: kcontrol/toplevel.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kcontrol/toplevel.cpp,v
retrieving revision 1.122
diff -u -r1.122 toplevel.cpp
--- kcontrol/toplevel.cpp	21 Oct 2003 15:25:46 -0000	1.122
+++ kcontrol/toplevel.cpp	20 Jan 2004 22:04:37 -0000
@@ -383,7 +383,9 @@
 
   _active=mod;
 
-  if (mod->aboutData())
+  const KAboutData *ad;
+  ad = mod->aboutData();
+  if (ad)
   {
      about_module->setText(i18n("Help menu->about <modulename>", "About %1").arg(
                              handleAmpersand( mod->moduleName())));
@@ -396,6 +398,7 @@
      about_module->setIconSet(QIconSet());
      about_module->setEnabled(false);
   }
+  delete ad;
 }
 
 void TopLevel::deleteDummyAbout()
@@ -422,8 +425,10 @@
         dummyAbout = const_cast<KAboutData*>(KGlobal::instance()->aboutData());
     else
     {
-        if (_active->aboutData())
-            dummyAbout = const_cast<KAboutData*>(_active->aboutData());
+        const KAboutData *ad;
+        ad = _active->aboutData();
+        if (ad)
+            dummyAbout = const_cast<KAboutData*>(ad);
         else
         {
             snprintf(buffer, sizeof(buffer), "kcm%s", _active->library().latin1());
@@ -441,8 +446,11 @@
 
 void TopLevel::aboutModule()
 {
-    KAboutApplication dlg(_active->aboutData());
+    const KAboutData *ad;
+    ad = _active->aboutData();
+    KAboutApplication dlg(ad);
     dlg.exec();
+    delete ad;
 }
 
 QString TopLevel::handleAmpersand( QString modulename ) const
Index: kfontinst/kcmfontinst/KCmFontInst.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kfontinst/kcmfontinst/KCmFontInst.cpp,v
retrieving revision 1.17
diff -u -r1.17 KCmFontInst.cpp
--- kfontinst/kcmfontinst/KCmFontInst.cpp	3 Dec 2003 15:26:26 -0000	1.17
+++ kfontinst/kcmfontinst/KCmFontInst.cpp	20 Jan 2004 22:04:41 -0000
@@ -66,7 +66,6 @@
 
 CKCmFontInst::CKCmFontInst(QWidget *parent, const char *, const QStringList&)
             : KCModule(parent, "kfontinst"),
-              itsAboutData(NULL),
               itsTop(CMisc::root() ? "fonts:/" : \
QString("fonts:/")+i18n(KIO_FONTS_USER)),  itsConfig("kcmfontinstuirc")
 {
@@ -338,8 +337,6 @@
     for(it=list.begin(), num=0; it!=list.end() && num<2; ++it, num++)
         itsConfig.writeEntry(0==num ? CFG_DIRSIZE : CFG_PREVIEWSIZE, *it);
 #endif
-    if(itsAboutData)
-        delete itsAboutData;
     delete itsDirOp;
 
     CGlobal::destroy();
@@ -347,20 +344,15 @@
 
 const KAboutData * CKCmFontInst::aboutData() const
 {
-    if(!itsAboutData)
-    {
-        CKCmFontInst *that = const_cast<CKCmFontInst *>(this);
-
-        that->itsAboutData=new KAboutData("kcmfontinst",
-                                          I18N_NOOP("KDE Font Installer"),
-                                          0, 0,
-                                          KAboutData::License_GPL,
-                                          I18N_NOOP("GUI front end to the fonts:/ \
                ioslave.\n"
-                                                    "(c) Craig Drummond, 2000 - \
                2003"));
-        that->itsAboutData->addAuthor("Craig Drummond", I18N_NOOP("Developer and \
                maintainer"), "craig@kde.org");
-    }
+    KAboutData *aboutData=new KAboutData("kcmfontinst",
+                             I18N_NOOP("KDE Font Installer"),
+                             0, 0,
+                             KAboutData::License_GPL,
+                             I18N_NOOP("GUI front end to the fonts:/ ioslave.\n"
+                             "(c) Craig Drummond, 2000 - 2003"));
+    aboutData->addAuthor("Craig Drummond", I18N_NOOP("Developer and maintainer"), \
"craig@kde.org");  
-    return itsAboutData;
+    return aboutData;
 }
 
 QString CKCmFontInst::quickHelp() const
Index: kfontinst/kcmfontinst/KCmFontInst.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/kfontinst/kcmfontinst/KCmFontInst.h,v
retrieving revision 1.6
diff -u -r1.6 KCmFontInst.h
--- kfontinst/kcmfontinst/KCmFontInst.h	3 Dec 2003 09:47:10 -0000	1.6
+++ kfontinst/kcmfontinst/KCmFontInst.h	20 Jan 2004 22:04:41 -0000
@@ -97,7 +97,6 @@
 
     private:
 
-    KAboutData   *itsAboutData;
     KDirOperator *itsDirOp;
     KURL         itsTop;
     KAction      *itsUpAct,
Index: knotify/knotify.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/knotify/knotify.cpp,v
retrieving revision 1.70
diff -u -r1.70 knotify.cpp
--- knotify/knotify.cpp	8 Nov 2003 23:43:51 -0000	1.70
+++ knotify/knotify.cpp	20 Jan 2004 22:04:44 -0000
@@ -187,18 +187,13 @@
 
 const KAboutData *KCMKNotify::aboutData() const
 {
-    static KAboutData* ab = 0;
-
-    if(!ab)
-    {
-        ab = new KAboutData(
-            "kcmnotify", I18N_NOOP("KNotify"), "3.0",
-            I18N_NOOP("System Notification Control Panel Module"),
-            KAboutData::License_GPL, "(c) 2002 Carsten Pfeiffer", 0, 0 );
-        ab->addAuthor( "Carsten Pfeiffer", 0, "pfeiffer@kde.org" );
-        ab->addCredit( "Charles Samuels", I18N_NOOP("Original implementation"),
-                       "charles@altair.dhs.org" );
-    }
+    KAboutData* ab = new KAboutData(
+        "kcmnotify", I18N_NOOP("KNotify"), "3.0",
+        I18N_NOOP("System Notification Control Panel Module"),
+        KAboutData::License_GPL, "(c) 2002 Carsten Pfeiffer", 0, 0 );
+    ab->addAuthor( "Carsten Pfeiffer", 0, "pfeiffer@kde.org" );
+    ab->addCredit( "Charles Samuels", I18N_NOOP("Original implementation"),
+                   "charles@altair.dhs.org" );
 
     return ab;
 }
Index: locale/toplevel.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/locale/toplevel.cpp,v
retrieving revision 1.56
diff -u -r1.56 toplevel.cpp
--- locale/toplevel.cpp	8 Nov 2003 23:43:52 -0000	1.56
+++ locale/toplevel.cpp	20 Jan 2004 22:04:45 -0000
@@ -46,8 +46,7 @@
 
 KLocaleApplication::KLocaleApplication(QWidget *parent, const char */*name*/, 
                                        const QStringList &args)
-  : KCModule( KLocaleFactory::instance(), parent, args),
-    m_aboutData(0)
+  : KCModule( KLocaleFactory::instance(), parent, args)
 {
   m_nullConfig = new KConfig(QString::null, false, false);
   m_globalConfig = new KConfig(QString::null, false, true);
@@ -141,7 +140,6 @@
   delete m_locale;
   delete m_globalConfig;
   delete m_nullConfig;
-  delete m_aboutData;
 }
 
 void KLocaleApplication::load()
@@ -268,21 +266,15 @@
 
 const KAboutData * KLocaleApplication::aboutData() const
 {
-  if ( ! m_aboutData )
-  {
-    KLocaleApplication * that = const_cast<KLocaleApplication *>(this);
-
-    that->m_aboutData = new KAboutData("kcmlocale",
-                                       I18N_NOOP("KCMLocale"),
-                                       "3.0",
-                                       I18N_NOOP("Regional settings"),
-                                       KAboutData::License_GPL,
-                                       "(C) 1998 Matthias Hoelzer, "
-                                       "(C) 1999-2003 Hans Petter Bieker",
-                                       0,
-                                       0,
-                                       "bieker@kde.org");
-  }
-
-  return m_aboutData;
+    KAboutData *aboutData = new KAboutData("kcmlocale",
+                               I18N_NOOP("KCMLocale"),
+                               "3.0",
+                                I18N_NOOP("Regional settings"),
+                                KAboutData::License_GPL,
+                                "(C) 1998 Matthias Hoelzer, "
+                                "(C) 1999-2003 Hans Petter Bieker",
+                                0,
+                                0,
+                                "bieker@kde.org");
+    return aboutData;
 }
Index: locale/toplevel.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/locale/toplevel.h,v
retrieving revision 1.14
diff -u -r1.14 toplevel.h
--- locale/toplevel.h	7 Mar 2003 22:05:32 -0000	1.14
+++ locale/toplevel.h	20 Jan 2004 22:04:45 -0000
@@ -80,7 +80,6 @@
 
   KConfig * m_globalConfig;
   KConfig * m_nullConfig;
-  KAboutData * m_aboutData;
 };
 
 typedef KGenericFactory<KLocaleApplication, QWidget > KLocaleFactory;
Index: screensaver/scrnsave.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/screensaver/scrnsave.cpp,v
retrieving revision 1.75
diff -u -r1.75 scrnsave.cpp
--- screensaver/scrnsave.cpp	10 Jan 2004 14:25:00 -0000	1.75
+++ screensaver/scrnsave.cpp	20 Jan 2004 22:04:51 -0000
@@ -411,6 +411,8 @@
         }
         delete mPreviewProc;
     }
+    mSaverList.setAutoDelete(true);
+    mSaverList.clear();
 
     delete mTestProc;
     delete mSetupProc;


["kcontrolPatchkrml" (text/x-diff)]

? kcontrolPatchkrml
Index: kmrml/kcontrol/kcmkmrml.cpp
===================================================================
RCS file: /home/kde/kdegraphics/kmrml/kmrml/kcontrol/kcmkmrml.cpp,v
retrieving revision 1.7
diff -u -r1.7 kcmkmrml.cpp
--- kmrml/kcontrol/kcmkmrml.cpp	27 Jul 2003 00:25:15 -0000	1.7
+++ kmrml/kcontrol/kcmkmrml.cpp	20 Jan 2004 22:04:20 -0000
@@ -103,21 +103,16 @@
 
 const KAboutData *KCMKMrml::aboutData() const
 {
-    static KAboutData* ab = 0;
-
-    if(!ab)
-    {
-        ab = new KAboutData(
-            "kcmkmrml",
-            I18N_NOOP("KCMKMrml"),
-            KMRML_VERSION,
-            I18N_NOOP("Advanced Search Control Module"),
-            KAboutData::License_GPL,
-            I18N_NOOP( "Copyright 2002, Carsten Pfeiffer" ),
-            0,
-            "http://devel-home.kde.org/~pfeiffer/kmrml/" );
-        ab->addAuthor( "Carsten Pfeiffer", 0, "pfeiffer@kde.org" );
-    }
+    KAboutData *ab = new KAboutData(
+        "kcmkmrml",
+         I18N_NOOP("KCMKMrml"),
+         KMRML_VERSION,
+         I18N_NOOP("Advanced Search Control Module"),
+         KAboutData::License_GPL,
+         I18N_NOOP( "Copyright 2002, Carsten Pfeiffer" ),
+         0,
+         "http://devel-home.kde.org/~pfeiffer/kmrml/" );
+    ab->addAuthor( "Carsten Pfeiffer", 0, "pfeiffer@kde.org" );
 
     return ab;
 }

["kcontrolPatchkrfb" (text/x-diff)]

? kcontrolPatchkrfb
Index: kcm_krfb/kcm_krfb.cpp
===================================================================
RCS file: /home/kde/kdenetwork/krfb/kcm_krfb/kcm_krfb.cpp,v
retrieving revision 1.18
diff -u -r1.18 kcm_krfb.cpp
--- kcm_krfb/kcm_krfb.cpp	10 Nov 2003 15:05:19 -0000	1.18
+++ kcm_krfb/kcm_krfb.cpp	20 Jan 2004 22:12:15 -0000
@@ -63,13 +63,6 @@
 
 	setButtons(Default|Apply|Reset);
 
-	m_about = new KAboutData( "kcm_krfb", I18N_NOOP("Desktop Sharing Control Module"),
-		VERSION,
-		I18N_NOOP("Configure desktop sharing"), KAboutData::License_GPL,
-		"(c) 2002, Tim Jansen\n",
-		0, "http://www.tjansen.de/krfb", "tim@tjansen.de");
-	m_about->addAuthor("Tim Jansen", 0, "tim@tjansen.de");
-
 	load();
 
 	connect(m_confWidget->passwordInput, SIGNAL(textChanged(const QString&)), SLOT(configChanged()) );
@@ -86,9 +79,6 @@
 	setInvitationNum(m_configuration.invitations().size());
 	connect(m_confWidget->disableBackgroundCB, SIGNAL(clicked()), SLOT(configChanged()) );
 }
-KcmKRfb::~KcmKRfb() {
-	delete m_about;
-}
 
 void KcmKRfb::configChanged() {
 	emit changed(true);
@@ -173,7 +163,14 @@
 
 const KAboutData *KcmKRfb::aboutData() const
 {
-	return m_about;
+	KAboutData *about = new KAboutData( "kcm_krfb", I18N_NOOP("Desktop Sharing Control Module"),
+		VERSION,
+		I18N_NOOP("Configure desktop sharing"), KAboutData::License_GPL,
+		"(c) 2002, Tim Jansen\n",
+		0, "http://www.tjansen.de/krfb", "tim@tjansen.de");
+	about->addAuthor("Tim Jansen", 0, "tim@tjansen.de");
+
+	return about;
 }
 
 QString KcmKRfb::quickHelp() const
Index: kcm_krfb/kcm_krfb.h
===================================================================
RCS file: /home/kde/kdenetwork/krfb/kcm_krfb/kcm_krfb.h,v
retrieving revision 1.5
diff -u -r1.5 kcm_krfb.h
--- kcm_krfb/kcm_krfb.h	1 May 2002 18:33:34 -0000	1.5
+++ kcm_krfb/kcm_krfb.h	20 Jan 2004 22:12:15 -0000
@@ -30,11 +30,9 @@
 private:
 	Configuration m_configuration;
 	ConfigurationWidget *m_confWidget;
-	KAboutData *m_about;
 	void checkKInetd(bool&, bool&);
 public:
 	KcmKRfb(QWidget *p, const char *name, const QStringList &);
-	~KcmKRfb();
 
 	void load();
 	void save();


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

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