From f9d932774e06d5122c48b47d8cabd791783f56d2 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 19 Jun 2009 17:00:27 -0700 Subject: fix a memory corruption where a SF Client could be used after it's been destroyed --- libs/surfaceflinger/LayerBase.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'libs/surfaceflinger/LayerBase.cpp') diff --git a/libs/surfaceflinger/LayerBase.cpp b/libs/surfaceflinger/LayerBase.cpp index b65c983869..3b86350667 100644 --- a/libs/surfaceflinger/LayerBase.cpp +++ b/libs/surfaceflinger/LayerBase.cpp @@ -640,16 +640,17 @@ regular: // --------------------------------------------------------------------------- LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, - Client* c, int32_t i) - : LayerBase(flinger, display), client(c), - lcblk( c ? &(c->ctrlblk->layers[i]) : 0 ), + const sp& client, int32_t i) + : LayerBase(flinger, display), client(client), + lcblk( client!=0 ? &(client->ctrlblk->layers[i]) : 0 ), mIndex(i) { } void LayerBaseClient::onFirstRef() { - if (client) { + sp client(this->client.promote()); + if (client != 0) { client->bindLayer(this, mIndex); // Initialize this layer's control block memset(this->lcblk, 0, sizeof(layer_cblk_t)); @@ -661,13 +662,16 @@ void LayerBaseClient::onFirstRef() LayerBaseClient::~LayerBaseClient() { - if (client) { + sp client(this->client.promote()); + if (client != 0) { client->free(mIndex); } } -int32_t LayerBaseClient::serverIndex() const { - if (client) { +int32_t LayerBaseClient::serverIndex() const +{ + sp client(this->client.promote()); + if (client != 0) { return (client->cid<<16)|mIndex; } return 0xFFFF0000 | mIndex; -- cgit v1.2.3-59-g8ed1b