[ekiga] Fixed a few crashes related to clicking on contacts/presentities



commit 7e726dd794c155f7146d6c2d4a35c15ed2e451a7
Author: Julien Puydt <jpuydt gnome org>
Date:   Sun Aug 30 09:04:32 2009 +0200

    Fixed a few crashes related to clicking on contacts/presentities
    
    Those are due to the fact that the reference counts aren't
    embedded anymore in the objects pointed to by smart pointers,
    so when we put a raw pointer in a gtk+ tree store, we must
    be careful not to put it back in a smart pointer which will
    kill it prematurely. Likewise, doing shared_ptr<Foo>(this)
    leads to a dead end unless one uses a null deleter.

 .../components/call-history/history-contact.cpp    |   12 +++++++-
 .../components/evolution/evolution-contact.cpp     |   12 +++++++-
 lib/engine/components/kab/kab-contact.cpp          |   12 +++++++-
 lib/engine/components/ldap/ldap-contact.cpp        |   13 +++++++-
 .../components/local-roster/local-presentity.cpp   |   12 +++++++-
 lib/engine/components/resource-list/rl-entry.cpp   |   12 +++++++-
 .../components/resource-list/rl-presentity.cpp     |   12 +++++++-
 lib/engine/gui/gtk-frontend/roster-view-gtk.cpp    |   32 ++++++++-----------
 lib/engine/presence/uri-presentity.cpp             |   12 +++++++-
 9 files changed, 103 insertions(+), 26 deletions(-)
---
diff --git a/lib/engine/components/call-history/history-contact.cpp b/lib/engine/components/call-history/history-contact.cpp
index 7129cd7..9798fd6 100644
--- a/lib/engine/components/call-history/history-contact.cpp
+++ b/lib/engine/components/call-history/history-contact.cpp
@@ -43,6 +43,16 @@
 
 #include "history-contact.h"
 
+/* at one point we will return a smart pointer on this... and if we don't use
+ * a false smart pointer, we will crash : the reference count isn't embedded!
+ */
+struct null_deleter
+{
+    void operator()(void const *) const
+    {
+    }
+};
+
 
 History::Contact::Contact (Ekiga::ServiceCore &_core,
 			   boost::shared_ptr<xmlDoc> _doc,
@@ -172,7 +182,7 @@ bool
 History::Contact::populate_menu (Ekiga::MenuBuilder &builder)
 {
   boost::shared_ptr<Ekiga::ContactCore> contact_core = core.get<Ekiga::ContactCore> ("contact-core");
-  return contact_core->populate_contact_menu (ContactPtr (this),
+  return contact_core->populate_contact_menu (ContactPtr (this, null_deleter ()),
 					      uri, builder);
 }
 
diff --git a/lib/engine/components/evolution/evolution-contact.cpp b/lib/engine/components/evolution/evolution-contact.cpp
index 5d0e58e..104e46a 100644
--- a/lib/engine/components/evolution/evolution-contact.cpp
+++ b/lib/engine/components/evolution/evolution-contact.cpp
@@ -41,6 +41,16 @@
 #include "form-request-simple.h"
 #include "menu-builder-tools.h"
 
+/* at one point we will return a smart pointer on this... and if we don't use
+ * a false smart pointer, we will crash : the reference count isn't embedded!
+ */
+struct null_deleter
+{
+    void operator()(void const *) const
+    {
+    }
+};
+
 Evolution::Contact::Contact (Ekiga::ServiceCore &_services,
 			     EBook *ebook,
 			     EContact *_econtact) : services(_services),
@@ -197,7 +207,7 @@ Evolution::Contact::populate_menu (Ekiga::MenuBuilder &builder)
       std::string attr_value = get_attribute_value (attr_type);
       if ( !attr_value.empty ()) {
 
-	if (core->populate_contact_menu (ContactPtr(this),
+	if (core->populate_contact_menu (ContactPtr(this, null_deleter ()),
 					 attr_value, tmp_builder)) {
 
 	  builder.add_ghost ("", get_attribute_name_from_type (attr_type));
diff --git a/lib/engine/components/kab/kab-contact.cpp b/lib/engine/components/kab/kab-contact.cpp
index 6614065..40743be 100644
--- a/lib/engine/components/kab/kab-contact.cpp
+++ b/lib/engine/components/kab/kab-contact.cpp
@@ -39,6 +39,16 @@
 
 #include "kab-contact.h"
 
+/* at one point we will return a smart pointer on this... and if we don't use
+ * a false smart pointer, we will crash : the reference count isn't embedded!
+ */
+struct null_deleter
+{
+    void operator()(void const *) const
+    {
+    }
+};
+
 KAB::Contact::Contact (Ekiga::ContactCore& _core,
 		       KABC::Addressee* addressee_)
   : core(_core), addressee(*addressee_)
@@ -71,7 +81,7 @@ KAB::Contact::populate_menu (Ekiga::MenuBuilder &builder)
 
     std::string precision = (*iter).typeLabel ().toUtf8 ().constData ();
     result = result
-      || core.populate_contact_menu (Ekiga::ContactPtr(this),
+      || core.populate_contact_menu (Ekiga::ContactPtr(this, null_deleter ()),
 				     (*iter).number ().toUtf8 ().constData (),
 				     builder);
   }
diff --git a/lib/engine/components/ldap/ldap-contact.cpp b/lib/engine/components/ldap/ldap-contact.cpp
index 6391cbe..954c475 100644
--- a/lib/engine/components/ldap/ldap-contact.cpp
+++ b/lib/engine/components/ldap/ldap-contact.cpp
@@ -41,6 +41,17 @@
 #include "ldap-contact.h"
 #include "menu-builder-tools.h"
 
+/* at one point we will return a smart pointer on this... and if we don't use
+ * a false smart pointer, we will crash : the reference count isn't embedded!
+ */
+struct null_deleter
+{
+    void operator()(void const *) const
+    {
+    }
+};
+
+
 OPENLDAP::Contact::Contact (Ekiga::ServiceCore &_core,
 			    const std::string _name,
 			    const std::map<std::string, std::string> _uris)
@@ -74,7 +85,7 @@ OPENLDAP::Contact::populate_menu (Ekiga::MenuBuilder &builder)
 	 = uris.begin ();
        iter != uris.end ();
        iter++) {
-    if (contact_core->populate_contact_menu (ContactPtr(this),
+    if (contact_core->populate_contact_menu (ContactPtr(this, null_deleter ()),
 					     iter->second, tmp_builder)) {
       builder.add_ghost ("", iter->first);
       tmp_builder.populate_menu (builder);
diff --git a/lib/engine/components/local-roster/local-presentity.cpp b/lib/engine/components/local-roster/local-presentity.cpp
index 2c4807c..e0fc946 100644
--- a/lib/engine/components/local-roster/local-presentity.cpp
+++ b/lib/engine/components/local-roster/local-presentity.cpp
@@ -42,6 +42,16 @@
 #include "robust-xml.h"
 #include "local-presentity.h"
 
+/* at one point we will return a smart pointer on this... and if we don't use
+ * a false smart pointer, we will crash : the reference count isn't embedded!
+ */
+struct null_deleter
+{
+    void operator()(void const *) const
+    {
+    }
+};
+
 
 /*
  * Public API
@@ -203,7 +213,7 @@ Local::Presentity::populate_menu (Ekiga::MenuBuilder &builder)
   boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
 
   populated
-    = presence_core->populate_presentity_menu (PresentityPtr(this),
+    = presence_core->populate_presentity_menu (PresentityPtr(this, null_deleter ()),
 					       get_uri (), builder);
 
   if (populated)
diff --git a/lib/engine/components/resource-list/rl-entry.cpp b/lib/engine/components/resource-list/rl-entry.cpp
index cd98d4b..eef7421 100644
--- a/lib/engine/components/resource-list/rl-entry.cpp
+++ b/lib/engine/components/resource-list/rl-entry.cpp
@@ -43,6 +43,16 @@
 
 #include "presence-core.h"
 
+/* at one point we will return a smart pointer on this... and if we don't use
+ * a false smart pointer, we will crash : the reference count isn't embedded!
+ */
+struct null_deleter
+{
+    void operator()(void const *) const
+    {
+    }
+};
+
 RL::Entry::Entry (Ekiga::ServiceCore& core_,
 		  boost::shared_ptr<XCAP::Path> path_,
 		  int pos,
@@ -145,7 +155,7 @@ RL::Entry::populate_menu (Ekiga::MenuBuilder& builder)
 		      boost::bind (&RL::Entry::refresh, this));
 
   if ( !uri.empty ())
-    populated = presence_core->populate_presentity_menu (Ekiga::PresentityPtr (this), uri, builder)
+    populated = presence_core->populate_presentity_menu (Ekiga::PresentityPtr (this, null_deleter), uri, builder)
       || populated;
 
   return populated;
diff --git a/lib/engine/components/resource-list/rl-presentity.cpp b/lib/engine/components/resource-list/rl-presentity.cpp
index 547bf01..fea6d8f 100644
--- a/lib/engine/components/resource-list/rl-presentity.cpp
+++ b/lib/engine/components/resource-list/rl-presentity.cpp
@@ -44,6 +44,16 @@
 
 #include "rl-presentity.h"
 
+/* at one point we will return a smart pointer on this... and if we don't use
+ * a false smart pointer, we will crash : the reference count isn't embedded!
+ */
+struct null_deleter
+{
+    void operator()(void const *) const
+    {
+    }
+};
+
 
 RL::Presentity::Presentity (Ekiga::ServiceCore &services_,
 			    boost::shared_ptr<XCAP::Path> path_,
@@ -193,7 +203,7 @@ RL::Presentity::populate_menu (Ekiga::MenuBuilder &builder)
   bool populated = false;
   boost::shared_ptr<Ekiga::PresenceCore> presence_core(services.get<Ekiga::PresenceCore> ("presence-core"));
 
-  populated = presence_core->populate_presentity_menu (PresentityPtr (this), uri, builder);
+  populated = presence_core->populate_presentity_menu (PresentityPtr (this, null_deleter ()), uri, builder);
 
   if (writable) {
 
diff --git a/lib/engine/gui/gtk-frontend/roster-view-gtk.cpp b/lib/engine/gui/gtk-frontend/roster-view-gtk.cpp
index 8769330..f034043 100644
--- a/lib/engine/gui/gtk-frontend/roster-view-gtk.cpp
+++ b/lib/engine/gui/gtk-frontend/roster-view-gtk.cpp
@@ -50,7 +50,6 @@
 #include "menu-builder-gtk.h"
 #include "form-dialog-gtk.h"
 
-
 /*
  * The Roster
  */
@@ -130,20 +129,20 @@ static void remove_child (GtkWidget* child,
 /* DESCRIPTION : Set of functions called when the user clicks in a view
  * BEHAVIOUR   : Folds/unfolds, shows a menu or triggers default action
  */
-static void on_clicked_show_heap_menu (Ekiga::HeapPtr heap,
+static void on_clicked_show_heap_menu (Ekiga::Heap* heap,
 				       GdkEventButton* event);
-static void on_clicked_show_heap_group_menu (Ekiga::HeapPtr heap,
+static void on_clicked_show_heap_group_menu (Ekiga::Heap* heap,
 					     const std::string name,
 					     GdkEventButton* event);
-static void on_clicked_show_presentity_menu (Ekiga::HeapPtr heap,
-					     Ekiga::PresentityPtr presentity,
+static void on_clicked_show_presentity_menu (Ekiga::Heap* heap,
+					     Ekiga::Presentity* presentity,
 					     GdkEventButton* event);
 
 static void on_clicked_fold (RosterViewGtk* self,
 			     GtkTreePath* path,
 			     const gchar* name);
 
-static void on_clicked_trigger_presentity (Ekiga::PresentityPtr presentity);
+static void on_clicked_trigger_presentity (Ekiga::Presentity* presentity);
 
 /* DESCRIPTION : Called whenever a (online/total) count has to be updated
  * BEHAVIOUR   : Updates things...
@@ -389,7 +388,7 @@ remove_child (GtkWidget* child,
 }
 
 static void
-on_clicked_show_heap_menu (Ekiga::HeapPtr heap,
+on_clicked_show_heap_menu (Ekiga::Heap* heap,
 			   GdkEventButton* event)
 {
   MenuBuilderGtk builder;
@@ -407,7 +406,7 @@ on_clicked_show_heap_menu (Ekiga::HeapPtr heap,
 }
 
 static void
-on_clicked_show_heap_group_menu (Ekiga::HeapPtr heap,
+on_clicked_show_heap_group_menu (Ekiga::Heap* heap,
 				 const std::string name,
 				 GdkEventButton* event)
 {
@@ -426,8 +425,8 @@ on_clicked_show_heap_group_menu (Ekiga::HeapPtr heap,
 }
 
 static void
-on_clicked_show_presentity_menu (Ekiga::HeapPtr heap,
-				 Ekiga::PresentityPtr presentity,
+on_clicked_show_presentity_menu (Ekiga::Heap* heap,
+				 Ekiga::Presentity* presentity,
 				 GdkEventButton* event)
 {
   Ekiga::TemporaryMenuBuilder temp;
@@ -491,7 +490,7 @@ on_clicked_fold (RosterViewGtk* self,
 }
 
 static void
-on_clicked_trigger_presentity (Ekiga::PresentityPtr presentity)
+on_clicked_trigger_presentity (Ekiga::Presentity* presentity)
 {
   Ekiga::TriggerMenuBuilder builder;
 
@@ -684,24 +683,21 @@ on_view_event_after (GtkWidget *tree_view,
 	if (event->type == GDK_BUTTON_PRESS && event->button == 1 && name)
 	  on_clicked_fold (self, path, name);
 	if (event->type == GDK_BUTTON_PRESS && event->button == 3)
-	  on_clicked_show_heap_menu (Ekiga::HeapPtr(heap), event);
+	  on_clicked_show_heap_menu (heap, event);
 	break;
       case TYPE_GROUP:
 
 	if (event->type == GDK_BUTTON_PRESS && event->button == 1 && name)
 	  on_clicked_fold (self, path, name);
 	if (event->type == GDK_BUTTON_PRESS && event->button == 3)
-	  on_clicked_show_heap_group_menu (Ekiga::HeapPtr(heap),
-					   name, event);
+	  on_clicked_show_heap_group_menu (heap, name, event);
 	break;
       case TYPE_PRESENTITY:
 
 	if (event->type == GDK_BUTTON_PRESS && event->button == 3)
-	  on_clicked_show_presentity_menu (Ekiga::HeapPtr(heap),
-					   Ekiga::PresentityPtr(presentity),
-					   event);
+	  on_clicked_show_presentity_menu (heap, presentity, event);
 	if (event->type == GDK_2BUTTON_PRESS)
-	  on_clicked_trigger_presentity (Ekiga::PresentityPtr(presentity));
+	  on_clicked_trigger_presentity (presentity);
 	break;
       default:
 
diff --git a/lib/engine/presence/uri-presentity.cpp b/lib/engine/presence/uri-presentity.cpp
index fbbcd2b..2478624 100644
--- a/lib/engine/presence/uri-presentity.cpp
+++ b/lib/engine/presence/uri-presentity.cpp
@@ -35,6 +35,16 @@
 
 #include "uri-presentity.h"
 
+/* at one point we will return a smart pointer on this... and if we don't use
+ * a false smart pointer, we will crash : the reference count isn't embedded!
+ */
+struct null_deleter
+{
+    void operator()(void const *) const
+    {
+    }
+};
+
 Ekiga::URIPresentity::URIPresentity (Ekiga::ServiceCore &_core,
 				     std::string name_,
 				     std::string uri_,
@@ -94,7 +104,7 @@ bool
 Ekiga::URIPresentity::populate_menu (Ekiga::MenuBuilder &builder)
 {
   boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
-  return presence_core->populate_presentity_menu (PresentityPtr(this),
+  return presence_core->populate_presentity_menu (PresentityPtr(this, null_deleter ()),
 						  uri, builder);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]