diff options
| author | Brandon Schaefer <brandon.schaefer@canonical.com> | 2012-10-15 19:08:37 +0000 |
|---|---|---|
| committer | Tarmac <> | 2012-10-15 19:08:37 +0000 |
| commit | 9706439c58c88f5b2040647b42b629f69a072cd1 (patch) | |
| tree | f892e7b8c3e91be77f9d9c7562321680e7abb106 /plugins/unity-mt-grab-handles | |
| parent | 537a2ee6d529b49ffb311f10bec25bf68c93fa7c (diff) | |
| parent | 246cd9d5828a16e89b12d179501011e646b004b6 (diff) | |
Fix reference counting problem which leads to memory leaks and a crash in MT grab handles.. Fixes: https://bugs.launchpad.net/bugs/1046201. Approved by Marco Trevisan (Treviño), Łukasz Zemczak.
(bzr r2841)
Diffstat (limited to 'plugins/unity-mt-grab-handles')
11 files changed, 48 insertions, 53 deletions
diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp index 64bd42521..146153416 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp @@ -40,7 +40,7 @@ unity::MT::GrabHandleGroup::hide() } void -unity::MT::GrabHandleGroup::raiseHandle(const boost::shared_ptr <const unity::MT::GrabHandle> &h) +unity::MT::GrabHandleGroup::raiseHandle(const std::shared_ptr <const unity::MT::GrabHandle> &h) { mOwner->raiseGrabHandle (h); } diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.h index 73f9a85db..93fe77cba 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.h +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.h @@ -22,9 +22,7 @@ #include <Nux/Nux.h> #include <glib.h> #include <boost/noncopyable.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> -#include <boost/weak_ptr.hpp> +#include <memory> #include "unity-mt-grab-handle.h" #include "unity-mt-texture.h" @@ -37,12 +35,12 @@ namespace MT extern unsigned int FADE_MSEC; class GrabHandleGroup : - public boost::enable_shared_from_this <GrabHandleGroup>, + public std::enable_shared_from_this <GrabHandleGroup>, boost::noncopyable { public: - typedef boost::shared_ptr <GrabHandleGroup> Ptr; + typedef std::shared_ptr <GrabHandleGroup> Ptr; static GrabHandleGroup::Ptr create (GrabHandleWindow *owner, std::vector<TextureSize> &textures); @@ -59,7 +57,7 @@ public: void hide(); void show(unsigned int handles = ~0); - void raiseHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &); + void raiseHandle (const std::shared_ptr <const unity::MT::GrabHandle> &); std::vector <TextureLayout> layout(unsigned int handles); diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp index 83aa4a692..c43fa9ab0 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp @@ -19,9 +19,9 @@ #include "unity-mt-grab-handle-impl-factory.h" #include "unity-mt-grab-handle.h" -boost::shared_ptr <unity::MT::GrabHandle::ImplFactory> unity::MT::GrabHandle::ImplFactory::mDefault; +std::shared_ptr <unity::MT::GrabHandle::ImplFactory> unity::MT::GrabHandle::ImplFactory::mDefault; -boost::shared_ptr <unity::MT::GrabHandle::ImplFactory> +std::shared_ptr <unity::MT::GrabHandle::ImplFactory> unity::MT::GrabHandle::ImplFactory::Default() { return mDefault; diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.h index ee93ed6b7..f8142a6fe 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.h +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.h @@ -22,9 +22,7 @@ #include <Nux/Nux.h> #include <glib.h> #include <boost/noncopyable.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> -#include <boost/weak_ptr.hpp> +#include <memory> #include "unity-mt-grab-handle.h" @@ -38,7 +36,7 @@ class GrabHandle::ImplFactory virtual ~ImplFactory() {}; - static boost::shared_ptr <ImplFactory> + static std::shared_ptr <ImplFactory> Default(); static void @@ -48,7 +46,7 @@ class GrabHandle::ImplFactory protected: - static boost::shared_ptr <ImplFactory> mDefault; + static std::shared_ptr <ImplFactory> mDefault; ImplFactory() {}; }; diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-window.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-window.h index 24e18da85..7a0373e19 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-window.h +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-window.h @@ -37,7 +37,7 @@ class GrabHandleWindow int y, unsigned int direction, unsigned int button) = 0; - virtual void raiseGrabHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &) = 0; + virtual void raiseGrabHandle (const std::shared_ptr <const unity::MT::GrabHandle> &) = 0; }; }; diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp index b1cb13349..ba523376b 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp @@ -55,7 +55,7 @@ void unity::MT::GrabHandle::raise () const { unity::MT::GrabHandleGroup::Ptr ghg = mOwner.lock (); - boost::shared_ptr <const unity::MT::GrabHandle> gh = shared_from_this (); + std::shared_ptr <const unity::MT::GrabHandle> gh = shared_from_this (); ghg->raiseHandle (gh); } @@ -98,7 +98,7 @@ unity::MT::GrabHandle::layout() unity::MT::GrabHandle::GrabHandle(Texture::Ptr texture, unsigned int width, unsigned int height, - const boost::shared_ptr <GrabHandleGroup> &owner, + const std::shared_ptr <GrabHandleGroup> &owner, unsigned int id) : mOwner(owner), mTexture (texture), @@ -110,7 +110,7 @@ unity::MT::GrabHandle::GrabHandle(Texture::Ptr texture, unity::MT::GrabHandle::Ptr unity::MT::GrabHandle::create (Texture::Ptr texture, unsigned int width, unsigned int height, - const boost::shared_ptr <GrabHandleGroup> &owner, + const std::shared_ptr <GrabHandleGroup> &owner, unsigned int id) { unity::MT::GrabHandle::Ptr p (new unity::MT::GrabHandle (texture, width, height, owner, id)); diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.h index d0221393a..946cefab0 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.h +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.h @@ -21,10 +21,8 @@ #include <Nux/Nux.h> #include <glib.h> +#include <memory> #include <boost/noncopyable.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> -#include <boost/weak_ptr.hpp> #include "unity-mt-texture.h" #include "unity-mt-grab-handle-window.h" @@ -79,17 +77,17 @@ static const std::map <int, unsigned int> handlesMask = { class GrabHandleGroup; class GrabHandle : - public boost::enable_shared_from_this <GrabHandle>, + public std::enable_shared_from_this <GrabHandle>, boost::noncopyable { public: - typedef boost::shared_ptr <GrabHandle> Ptr; + typedef std::shared_ptr <GrabHandle> Ptr; static GrabHandle::Ptr create (Texture::Ptr texture, unsigned int width, unsigned int height, - const boost::shared_ptr <GrabHandleGroup> &owner, + const std::shared_ptr <GrabHandleGroup> &owner, unsigned int id); ~GrabHandle(); @@ -160,10 +158,10 @@ private: GrabHandle(Texture::Ptr texture, unsigned int width, unsigned int height, - const boost::shared_ptr <GrabHandleGroup> &owner, + const std::shared_ptr <GrabHandleGroup> &owner, unsigned int id); - boost::weak_ptr <GrabHandleGroup> mOwner; + std::weak_ptr <GrabHandleGroup> mOwner; Texture::Ptr mTexture; unsigned int mId; nux::Geometry mRect; diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp index e16cb89c3..c4ff2c333 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp @@ -35,7 +35,8 @@ unity::MT::X11TextureFactory::setActiveWrap (const GLTexture::List &t) unity::MT::Texture::Ptr unity::MT::X11TextureFactory::create () { - return boost::shared_static_cast <unity::MT::Texture> (unity::MT::X11Texture::Ptr (new unity::MT::X11Texture (mWrap))); + unity::MT::Texture::Ptr tp(static_cast<unity::MT::Texture*> (new unity::MT::X11Texture(mWrap))); + return tp; } unity::MT::X11Texture::X11Texture (const GLTexture::List &t) @@ -151,7 +152,7 @@ unity::MT::X11GrabHandleImpl::buttonPress (int x, } void -UnityMTGrabHandlesWindow::raiseGrabHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &h) +UnityMTGrabHandlesWindow::raiseGrabHandle (const std::shared_ptr <const unity::MT::GrabHandle> &h) { UnityMTGrabHandlesScreen::get (screen)->raiseHandle (h, window->frame ()); } @@ -202,12 +203,13 @@ sortPointers(void *p1, void *p2) } void -UnityMTGrabHandlesScreen::raiseHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &h, +UnityMTGrabHandlesScreen::raiseHandle (const std::shared_ptr <const unity::MT::GrabHandle> &h, Window owner) { for (const auto &pair : mInputHandles) { - if (*pair.second == *h) + const unity::MT::GrabHandle::Ptr gh = pair.second.lock(); + if (*gh == *h) { unsigned int mask = CWSibling | CWStackMode; XWindowChanges xwc; @@ -322,10 +324,11 @@ UnityMTGrabHandlesScreen::handleEvent(XEvent* event) if (it != mInputHandles.end()) { - if (it->second) - it->second->buttonPress (event->xbutton.x_root, - event->xbutton.y_root, - event->xbutton.button); + const unity::MT::GrabHandle::Ptr gh = it->second.lock(); + if (gh) + gh->buttonPress (event->xbutton.x_root, + event->xbutton.y_root, + event->xbutton.button); } break; @@ -346,8 +349,9 @@ UnityMTGrabHandlesScreen::handleEvent(XEvent* event) if (it != mInputHandles.end()) { - if (it->second) - it->second->reposition (0, 0, unity::MT::PositionLock); + const unity::MT::GrabHandle::Ptr gh = it->second.lock(); + if (gh) + gh->reposition (0, 0, unity::MT::PositionLock); } break; @@ -457,7 +461,7 @@ UnityMTGrabHandlesWindow::glDraw(const GLMatrix& transform, * region */ CompRegion reg = CompRegion(layout.second.x, layout.second.y, layout.second.width, layout.second.height); - for(GLTexture * tex : boost::shared_static_cast <unity::MT::X11Texture> (layout.first)->get ()) + for(GLTexture * tex : static_cast<unity::MT::X11Texture*>(layout.first.get())->get()) { GLTexture::MatrixList matl; GLTexture::Matrix mat = tex->matrix(); @@ -633,7 +637,7 @@ UnityMTGrabHandlesWindow::restackHandles() void UnityMTGrabHandlesScreen::addHandleWindow(const unity::MT::GrabHandle::Ptr &h, Window w) { - mInputHandles.insert(std::pair <Window, const unity::MT::GrabHandle::Ptr> (w, h)); + mInputHandles.insert(std::make_pair(w, h)); } void @@ -774,7 +778,7 @@ UnityMTGrabHandlesScreen::UnityMTGrabHandlesScreen(CompScreen* s) : GLTexture::List t = GLTexture::readImageToTexture(fname, pname, size); - (boost::shared_static_cast <unity::MT::X11TextureFactory> (unity::MT::Texture::Factory::Default ()))->setActiveWrap (t); + (static_cast<unity::MT::X11TextureFactory*>(unity::MT::Texture::Factory::Default().get())->setActiveWrap(t)); mHandleTextures.at(i).first = unity::MT::Texture::Factory::Default ()->create (); mHandleTextures.at (i).second.width = size.width (); diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.h index f0d3776e5..4acf1d3f8 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.h +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.h @@ -22,9 +22,7 @@ #include <composite/composite.h> #include <opengl/opengl.h> #include <boost/noncopyable.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> -#include <boost/weak_ptr.hpp> +#include <memory> #include <core/atoms.h> @@ -72,7 +70,7 @@ class X11Texture : { public: - typedef boost::shared_ptr <X11Texture> Ptr; + typedef std::shared_ptr <X11Texture> Ptr; X11Texture (const GLTexture::List &t); @@ -124,7 +122,7 @@ public: private: - boost::weak_ptr <unity::MT::GrabHandle> mGrabHandle; + std::weak_ptr <unity::MT::GrabHandle> mGrabHandle; Window mIpw; Display *mDpy; }; @@ -175,7 +173,7 @@ public: void preparePaint(int); void donePaint(); - void raiseHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &, + void raiseHandle (const std::shared_ptr <const unity::MT::GrabHandle> &, Window owner); std::vector <unity::MT::TextureSize> & textures() @@ -188,7 +186,7 @@ private: std::list <unity::MT::GrabHandleGroup::Ptr> mGrabHandles; std::vector <unity::MT::TextureSize> mHandleTextures; - std::map <Window, const unity::MT::GrabHandle::Ptr> mInputHandles; + std::map <Window, const std::weak_ptr <unity::MT::GrabHandle> > mInputHandles; CompWindowVector mLastClientListStacking; Atom mCompResizeWindowAtom; @@ -243,7 +241,7 @@ public: protected: - void raiseGrabHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &h); + void raiseGrabHandle (const std::shared_ptr <const unity::MT::GrabHandle> &h); void requestMovement (int x, int y, unsigned int direction, diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp index c87076652..e6a1e1c0d 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp +++ b/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp @@ -18,7 +18,7 @@ #include "unity-mt-texture.h" -boost::shared_ptr <unity::MT::Texture::Factory> unity::MT::Texture::Factory::mDefault; +std::shared_ptr <unity::MT::Texture::Factory> unity::MT::Texture::Factory::mDefault; unity::MT::Texture::Factory::Factory () { @@ -34,7 +34,7 @@ unity::MT::Texture::Factory::SetDefault (Factory *f) mDefault.reset (f); } -boost::shared_ptr <unity::MT::Texture::Factory> +std::shared_ptr <unity::MT::Texture::Factory> unity::MT::Texture::Factory::Default () { return mDefault; diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-texture.h b/plugins/unity-mt-grab-handles/src/unity-mt-texture.h index 2d9a26531..990e73609 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-texture.h +++ b/plugins/unity-mt-grab-handles/src/unity-mt-texture.h @@ -21,7 +21,6 @@ #include <Nux/Nux.h> #include <boost/noncopyable.hpp> -#include <boost/shared_ptr.hpp> namespace unity { @@ -31,7 +30,7 @@ class Texture { public: - typedef boost::shared_ptr <Texture> Ptr; + typedef std::shared_ptr <Texture> Ptr; virtual ~Texture (); @@ -48,7 +47,7 @@ class Texture static void SetDefault (Factory *); - static boost::shared_ptr <Factory> + static std::shared_ptr <Factory> Default (); protected: @@ -57,7 +56,7 @@ class Texture private: - static boost::shared_ptr <unity::MT::Texture::Factory> mDefault; + static std::shared_ptr <unity::MT::Texture::Factory> mDefault; }; protected: |
