From ce8e5df3c11616f3eb7867ce89558b530651166c Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 28 Apr 2016 10:12:47 -0700 Subject: [PATCH] Don't flatten nullptrs Bug: 28428970 BufferQueueProducer can return a nullptr for the GraphicBuffer if there's nothing queued, which IGraphicBufferProducer would attempt to flatten. It's useful to distinguish that there's nothing queued instead of just generic error, so fix IGraphicBufferProducer to handle null GraphicBuffers. Change-Id: I9e2b11e107e093d209a89a01d14feec3e885f268 --- libs/gui/IGraphicBufferProducer.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index c36fcadf9f..137a54bcfb 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -395,8 +395,12 @@ public: if (result != NO_ERROR) { return result; } - sp buffer(new GraphicBuffer); - result = reply.read(*buffer); + bool hasBuffer = reply.readBool(); + sp buffer; + if (hasBuffer) { + buffer = new GraphicBuffer(); + result = reply.read(*buffer); + } if (result != NO_ERROR) { ALOGE("getLastQueuedBuffer failed to read buffer: %d", result); return result; @@ -631,7 +635,12 @@ status_t BnGraphicBufferProducer::onTransact( if (result != NO_ERROR) { return result; } - result = reply->write(*buffer); + if (!buffer.get()) { + reply->writeBool(false); + } else { + reply->writeBool(true); + result = reply->write(*buffer); + } if (result != NO_ERROR) { ALOGE("getLastQueuedBuffer failed to write buffer: %d", result); return result; -- 2.11.0