Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e09dcdba authored by Zhijun He's avatar Zhijun He
Browse files

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
parent 500f7811
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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;
            }