[v3,8/8] libcamera: egl: initEGLContext(): Avoid double init
diff mbox series

Message ID 20260811130042.213139-9-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: software_isp: debayer_egl: Remove some leaks
Related show

Commit Message

Barnabás Pőcze Aug. 11, 2026, 1 p.m. UTC
If the initialization is already done, reject further attempts,
otherwise resources would be leaked.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/libcamera/egl.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
index 1f9e743c2f..410d27b98c 100644
--- a/src/libcamera/egl.cpp
+++ b/src/libcamera/egl.cpp
@@ -371,7 +371,10 @@  void eGL::createOutputTexture2D(eGLImage &eglImage)
  *
  * Each successful invocation must be followed by a call to resetEGLContext().
  *
- * \return 0 on success, or -ENODEV on failure
+ * If a valid EGL context is already present, initialization attempts
+ * will be rejected.
+ *
+ * \return 0 on success, or negative error code on failure
  */
 int eGL::initEGLContext()
 {
@@ -394,6 +397,9 @@  int eGL::initEGLContext()
 	EGLint numConfigs;
 	EGLConfig config;
 
+	if (context_ != EGL_NO_CONTEXT)
+		return -EEXIST;
+
 	if (!eglBindAPI(EGL_OPENGL_ES_API)) {
 		LOG(eGL, Error) << "API bind fail";
 		goto fail;