egl: Fix leaks in eglReleaseThread.
authorChia-I Wu <olvaffe@gmail.com>
Tue, 26 Jan 2010 09:22:21 +0000 (17:22 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Tue, 26 Jan 2010 10:46:05 +0000 (18:46 +0800)
There may be multiple bound contexts that should be unbound.

src/egl/main/eglapi.c

index c197cfd38f47d9d01f7a93b10fa34b86ee1aebe1..2e5027a32e61814edd672f2ea9f6ce25580b47bc 100644 (file)
@@ -984,13 +984,20 @@ eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
 EGLBoolean
 eglReleaseThread(void)
 {
-   /* unbind current context */
+   /* unbind current contexts */
    if (!_eglIsCurrentThreadDummy()) {
-      _EGLDisplay *disp = _eglGetCurrentDisplay();
-      _EGLDriver *drv;
-      if (disp) {
-         drv = disp->Driver;
-         (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
+      _EGLThreadInfo *t = _eglGetCurrentThread();
+      EGLint i;
+
+      for (i = 0; i < _EGL_API_NUM_APIS; i++) {
+         _EGLContext *ctx = t->CurrentContexts[i];
+         if (ctx) {
+            _EGLDisplay *disp = ctx->Resource.Display;
+            _EGLDriver *drv = disp->Driver;
+            /* what if drv is not avaialbe? */
+            if (drv)
+               (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
+         }
       }
    }