Mesa (master): mesa: Avoid leaking surface in st_renderbuffer_delete

Emil Velikov evelikov at kemper.freedesktop.org
Tue May 30 13:50:25 UTC 2017


Module: Mesa
Branch: master
Commit: fd6c2a3f3eb7f5f3077fb95b1441ddaa43b806fe
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd6c2a3f3eb7f5f3077fb95b1441ddaa43b806fe

Author: Bartosz Tomczyk <bartosz.tomczyk86 at gmail.com>
Date:   Sat Apr 29 16:37:45 2017 +0200

mesa: Avoid leaking surface in st_renderbuffer_delete

v2: add comment in code

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100741
Fixes: a5e733c6b52 mesa: drop current draw/read buffer when ctx is released
Reviewed-by: Rob Clark <robdclark at gmail.com> (v1)
Reviewed-by: Emil Velikov <emil.velikov at collabora.com>

---

 src/mesa/main/context.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 3570f94f5a..9aa6fb64b2 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1664,17 +1664,23 @@ _mesa_make_current( struct gl_context *newCtx,
       _mesa_flush(curCtx);
 
    /* We used to call _glapi_check_multithread() here.  Now do it in drivers */
-   _glapi_set_context((void *) newCtx);
-   assert(_mesa_get_current_context() == newCtx);
 
    if (!newCtx) {
       _glapi_set_dispatch(NULL);  /* none current */
+      /* We need old ctx to correctly release Draw/ReadBuffer
+       * and avoid a surface leak in st_renderbuffer_delete.
+       * Therefore, first drop buffers then set new ctx to NULL.
+       */
       if (curCtx) {
          _mesa_reference_framebuffer(&curCtx->WinSysDrawBuffer, NULL);
          _mesa_reference_framebuffer(&curCtx->WinSysReadBuffer, NULL);
       }
+      _glapi_set_context(NULL);
+      assert(_mesa_get_current_context() == NULL);
    }
    else {
+      _glapi_set_context((void *) newCtx);
+      assert(_mesa_get_current_context() == newCtx);
       _glapi_set_dispatch(newCtx->CurrentClientDispatch);
 
       if (drawBuffer && readBuffer) {




More information about the mesa-commit mailing list