free gralloc buffers as soon as possible (when a surface is not visible any longer), client who have the buffers still mapped won't crash, btu may see garbage data
diff --git a/libs/surfaceflinger/LayerBitmap.cpp b/libs/surfaceflinger/LayerBitmap.cpp
index a368ca9..e0984fe 100644
--- a/libs/surfaceflinger/LayerBitmap.cpp
+++ b/libs/surfaceflinger/LayerBitmap.cpp
@@ -130,13 +130,10 @@
return res;
}
-
-
// ===========================================================================
// LayerBitmap
// ===========================================================================
-
LayerBitmap::LayerBitmap()
: mInfo(0), mWidth(0), mHeight(0)
{
@@ -184,7 +181,7 @@
sp<Buffer> buffer(mBuffer);
const uint32_t w = mWidth;
const uint32_t h = mHeight;
- if (w != buffer->getWidth() || h != buffer->getHeight()) {
+ if (buffer!=0 && (w != buffer->getWidth() || h != buffer->getHeight())) {
surface_info_t* info = mInfo;
buffer = new Buffer(w, h, mFormat, mFlags);
status_t err = buffer->initCheck();
@@ -200,6 +197,15 @@
return buffer;
}
+status_t LayerBitmap::free()
+{
+ mBuffer.clear();
+ mWidth = 0;
+ mHeight = 0;
+ return NO_ERROR;
+}
+
+
// ---------------------------------------------------------------------------
}; // namespace android