Code

fix leak and potential crash by disconnecting on delete
authorbuliabyak <buliabyak@users.sourceforge.net>
Sat, 20 Sep 2008 21:02:26 +0000 (21:02 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Sat, 20 Sep 2008 21:02:26 +0000 (21:02 +0000)
src/selection-describer.cpp
src/selection-describer.h

index 6d80cfe5c0152a1178ea7b23438e04d0d262e78f..bd84030543fb2a6a62b45046a16fe464c1d28613 100644 (file)
@@ -97,10 +97,18 @@ namespace Inkscape {
 SelectionDescriber::SelectionDescriber(Inkscape::Selection *selection, MessageStack *stack)
 : _context(stack)
 {
-    selection->connectChanged(sigc::mem_fun(*this, &SelectionDescriber::_updateMessageFromSelection));
+    _selection_changed_connection = new sigc::connection (
+             selection->connectChanged(
+                 sigc::mem_fun(*this, &SelectionDescriber::_updateMessageFromSelection)));
     _updateMessageFromSelection(selection);
 }
 
+SelectionDescriber::~SelectionDescriber()
+{
+    _selection_changed_connection->disconnect();
+    delete _selection_changed_connection;
+}
+
 void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *selection) {
     GSList const *items = selection->itemList();
 
index cd892bd14585d3f688620fb15fa3cfef1bd3b9f0..91948c2fd325f0bb0bf7da2694ab6a7b39bdd105 100644 (file)
@@ -24,10 +24,13 @@ class MessageStack;
 class SelectionDescriber : public sigc::trackable {
 public:
     SelectionDescriber(Inkscape::Selection *selection, MessageStack *stack);
+    ~SelectionDescriber();
 
 private:
     void _updateMessageFromSelection(Inkscape::Selection *selection);
 
+    sigc::connection *_selection_changed_connection;
+
     MessageContext _context;
 };