From 72c8020b8036c0f4dce9ce6c0e269a29624ed6f2 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 16 Jun 2014 01:02:03 +0200 Subject: add proper refcounting to XML SignalObserver. not refcounting caused crash upon opening Filter Editor dialog for the first time with a filtered object selected. Fixed bugs: - https://launchpad.net/bugs/1328152 (bzr r13426) --- src/xml/helper-observer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/xml') diff --git a/src/xml/helper-observer.cpp b/src/xml/helper-observer.cpp index c54dd8e74..e56ddc6f8 100644 --- a/src/xml/helper-observer.cpp +++ b/src/xml/helper-observer.cpp @@ -5,7 +5,7 @@ namespace XML { // Very simple observer that just emits a signal if anything happens to a node SignalObserver::SignalObserver() - : _oldsel(0) + : _oldsel(NULL) {} // Add this observer to the SPObject and remove it from any previous object @@ -13,17 +13,21 @@ void SignalObserver::set(SPObject* o) { // XML Tree being used direcly in this function in the following code // while it shouldn't be + // Pointer to object is stored, so refcounting should be increased/decreased if(_oldsel) { if (_oldsel->getRepr()) { _oldsel->getRepr()->removeObserver(*this); } + sp_object_unref(_oldsel); + _oldsel = NULL; } if(o) { if (o->getRepr()) { o->getRepr()->addObserver(*this); + sp_object_ref(o); + _oldsel = o; } } - _oldsel = o; } void SignalObserver::notifyChildAdded(XML::Node&, XML::Node&, XML::Node*) -- cgit v1.2.3