[RenderEngine] Release the fence before calling eglCreateSyncKHR.
Previously we released the fence after calling eglCreateSyncKHR, however if
eglCreateSyncKHR fails, then we will return, which results in double free of
the fd. This patch makes sure we release fd before we transfer the ownership to
EGLSync.
BUG: 131290710
Test: Boot
Change-Id: I4d8cb7968ceceac5b910d4cb43e94b330319071f
diff --git a/libs/renderengine/gl/GLESRenderEngine.cpp b/libs/renderengine/gl/GLESRenderEngine.cpp
index faf6d2a..48cb620 100644
--- a/libs/renderengine/gl/GLESRenderEngine.cpp
+++ b/libs/renderengine/gl/GLESRenderEngine.cpp
@@ -540,16 +540,14 @@
return false;
}
- EGLint attribs[] = {EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceFd, EGL_NONE};
+ // release the fd and transfer the ownership to EGLSync
+ EGLint attribs[] = {EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fenceFd.release(), EGL_NONE};
EGLSyncKHR sync = eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
if (sync == EGL_NO_SYNC_KHR) {
ALOGE("failed to create EGL native fence sync: %#x", eglGetError());
return false;
}
- // fenceFd is now owned by EGLSync
- (void)fenceFd.release();
-
// XXX: The spec draft is inconsistent as to whether this should return an
// EGLint or void. Ignore the return value for now, as it's not strictly
// needed.