ImageReader: free direct byte buffers once Image is returned

This can prevent apps from accessing an image byte buffer when it is closed.

Bug: 12528089
Change-Id: I04dccf1832204be2ae3aeb3bbe04f616886447e6
This commit is contained in:
Zhijun He
2014-11-26 13:24:48 -08:00
parent 500f781110
commit e09dcdba71

View File

@@ -26,6 +26,7 @@ import android.view.Surface;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.NioUtils;
/**
* <p>The ImageReader class allows direct application access to image data
@@ -688,6 +689,15 @@ public class ImageReader implements AutoCloseable {
}
private void clearBuffer() {
// Need null check first, as the getBuffer() may not be called before an image
// is closed.
if (mBuffer == null) {
return;
}
if (mBuffer.isDirect()) {
NioUtils.freeDirectBuffer(mBuffer);
}
mBuffer = null;
}