summaryrefslogtreecommitdiffstats
path: root/libs/surfaceflinger/LayerBase.cpp
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2009-06-19 17:00:27 -0700
committerMathias Agopian <mathias@google.com>2009-06-19 17:00:27 -0700
commit6edf5af578c1ab1fcd44b7c08ca371456e4b7430 (patch)
tree28ae8dec57019f5aac653b1a2d4df5cd061ee976 /libs/surfaceflinger/LayerBase.cpp
parentc8fb5b1979da4829e1486e6a1008c06c979b94b0 (diff)
downloadframeworks_base-6edf5af578c1ab1fcd44b7c08ca371456e4b7430.zip
frameworks_base-6edf5af578c1ab1fcd44b7c08ca371456e4b7430.tar.gz
frameworks_base-6edf5af578c1ab1fcd44b7c08ca371456e4b7430.tar.bz2
fix a memory corruption where a SF Client could be used after it's been destroyed
Diffstat (limited to 'libs/surfaceflinger/LayerBase.cpp')
-rw-r--r--libs/surfaceflinger/LayerBase.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/libs/surfaceflinger/LayerBase.cpp b/libs/surfaceflinger/LayerBase.cpp
index b65c983..3b86350 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>& 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> 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> client(this->client.promote());
+ if (client != 0) {
client->free(mIndex);
}
}
-int32_t LayerBaseClient::serverIndex() const {
- if (client) {
+int32_t LayerBaseClient::serverIndex() const
+{
+ sp<Client> client(this->client.promote());
+ if (client != 0) {
return (client->cid<<16)|mIndex;
}
return 0xFFFF0000 | mIndex;