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

List:       kde-devel
Subject:    kopete walletmanager static destruction order
From:       Michael Leupold <lemma () confuego ! org>
Date:       2008-10-28 14:39:45
Message-ID: 200810281539.53161.lemma () confuego ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi,

since I made kwalletd a binary of its own KWallet::Wallet makes sure the 
daemon is started if any application needs its service. It also maintains a 
static pointer to the dbus interface. That's where the actual fun starts.

Kopete uses a function static instance of its Kopete::WalletManager (which in 
turn uses KWallet::Wallet) to manage the connection to the wallet. If there's 
an open wallet connection on quitting kopete it is closed in 
Kopete::WalletManager's dtor. Unfortunately the static destruction sequence 
might destroy KWallet::Wallet's static dbus interface before Kopete gets to 
closing the wallet.

Now the main problem is that Kopete's connection to the wallet is never 
terminated leaving the wallet open unless the user has configured a timer to 
close it after a specified interval.

To fix this I made a patch for kopete some while ago (attached). It changes 
the WalletManager instance from function static to a static class member. 
Destruction is handled by connecting the aboutToQuit() signal to the 
instance's deleteLater() slot.

Now I figure this might not be the prettiest but do you think that's ok? I 
wouldn't mind if someone came up with a more elegant way either.

Regards,
Michael

["patch-kopete-walletmanager-crash.diff" (text/x-patch)]

Index: libkopete/kopetewalletmanager.h
===================================================================
--- libkopete/kopetewalletmanager.h	(Revision 824255)
+++ libkopete/kopetewalletmanager.h	(Arbeitskopie)
@@ -91,6 +91,8 @@
 	void openWalletInner();
 	void emitWalletOpened( KWallet::Wallet *wallet );
 
+	static WalletManager *s;
+
 	class Private;
 	Private *d;
 
Index: libkopete/kopetewalletmanager.cpp
===================================================================
--- libkopete/kopetewalletmanager.cpp	(Revision 824255)
+++ libkopete/kopetewalletmanager.cpp	(Arbeitskopie)
@@ -50,6 +50,8 @@
 	KopeteWalletSignal *signal;
 };
 
+Kopete::WalletManager *Kopete::WalletManager::s = 0;
+
 Kopete::WalletManager::WalletManager()
  : d( new Private )
 {
@@ -63,8 +65,11 @@
 
 Kopete::WalletManager *Kopete::WalletManager::self()
 {
-	static WalletManager s;
-	return &s;
+	if (!s) {
+		s = new WalletManager();
+		connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), s, SLOT(deleteLater()));
+	}
+	return s;
 }
 
 void Kopete::WalletManager::openWallet( QObject *object, const char *slot )

["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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