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

Message ID 20260810105942.1098192-8-barnabas.pocze@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: software_isp: debayer_egl: Remove some leaks
Related show

Commit Message

Barnabás Pőcze Aug. 10, 2026, 10:59 a.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>
---
 src/libcamera/egl.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jacopo Mondi Aug. 11, 2026, 9:32 a.m. UTC | #1
Hi Barnabás

On Mon, Aug 10, 2026 at 12:59:41PM +0200, Barnabás Pőcze wrote:
> 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>
> ---
>  src/libcamera/egl.cpp | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
> index 237791bca1..edb00ef997 100644
> --- a/src/libcamera/egl.cpp
> +++ b/src/libcamera/egl.cpp
> @@ -357,7 +357,7 @@ void eGL::createOutputTexture2D(eGLImage &eglImage)
>   * - eglCreateImageKHR / eglDestroyImageKHR
>   * - glEGLImageTargetTexture2DOES

Let's document that two consecutive invocations without a call to
resetEGLContext() are not valid

>   *
> - * \return 0 on success, or -ENODEV on failure
> + * \return 0 on success, or negative error code on failure
>   */
>  int eGL::initEGLContext()
>  {
> @@ -380,6 +380,9 @@ int eGL::initEGLContext()
>  	EGLint numConfigs;
>  	EGLConfig config;
>
> +	if (context_ != EGL_NO_CONTEXT)
> +		return -EEXIST;
> +

With the documentation update
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

>  	if (!eglBindAPI(EGL_OPENGL_ES_API)) {
>  		LOG(eGL, Error) << "API bind fail";
>  		goto fail;
> --
> 2.55.0
>

Patch
diff mbox series

diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
index 237791bca1..edb00ef997 100644
--- a/src/libcamera/egl.cpp
+++ b/src/libcamera/egl.cpp
@@ -357,7 +357,7 @@  void eGL::createOutputTexture2D(eGLImage &eglImage)
  * - eglCreateImageKHR / eglDestroyImageKHR
  * - glEGLImageTargetTexture2DOES
  *
- * \return 0 on success, or -ENODEV on failure
+ * \return 0 on success, or negative error code on failure
  */
 int eGL::initEGLContext()
 {
@@ -380,6 +380,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;