From a1f47b90ab53af978be45b8bda16c5d084ae66e6 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 15 Feb 2011 19:01:06 -0800 Subject: fix a surface leak in SurfaceFlinger SF kept a strong reference to ISurface until the window manager removed the surface from the screen. This fell appart when running standalone tests, that is when the window manager wasn't involved. When the window manager is around, it would clean-up surfaces even when an application died. with this change, SF is able to do its own cleanup without relying on the window manager. the change is very simple, we simply don't keep a reference to ISurface and make sure no more than one of them can be created. Change-Id: I61f2d7473bf8d4aa651549a846c34cdbb0d0c85a --- services/surfaceflinger/LayerBase.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'services/surfaceflinger/LayerBase.cpp') diff --git a/services/surfaceflinger/LayerBase.cpp b/services/surfaceflinger/LayerBase.cpp index 86057f8cd5..6025ed4921 100644 --- a/services/surfaceflinger/LayerBase.cpp +++ b/services/surfaceflinger/LayerBase.cpp @@ -540,7 +540,9 @@ int32_t LayerBaseClient::sIdentity = 1; LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, const sp& client) - : LayerBase(flinger, display), mClientRef(client), + : LayerBase(flinger, display), + mHasSurface(false), + mClientRef(client), mIdentity(uint32_t(android_atomic_inc(&sIdentity))) { } @@ -557,12 +559,13 @@ sp LayerBaseClient::getSurface() { sp s; Mutex::Autolock _l(mLock); - s = mClientSurface.promote(); - if (s == 0) { - s = createSurface(); - mClientSurface = s; - mClientSurfaceBinder = s->asBinder(); - } + + LOG_ALWAYS_FATAL_IF(mHasSurface, + "LayerBaseClient::getSurface() has already been called"); + + mHasSurface = true; + s = createSurface(); + mClientSurfaceBinder = s->asBinder(); return s; } -- cgit v1.2.3-59-g8ed1b