From ee025f56c0cdc300317fcc9b535270dc06931806 Mon Sep 17 00:00:00 2001
From: Stanislav Vorobiov <s.vorobiov@samsung.com>
Date: Thu, 22 Aug 2013 12:14:06 +0400
Subject: [PATCH] YaGL: Fixed framebuffers and renderbuffers leak

---
 hw/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.c | 2 ++
 hw/yagl_drivers/gles_onscreen/yagl_gles_onscreen.c        | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.c b/hw/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.c
index 9a672aead6..170f0b4d79 100644
--- a/hw/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.c
+++ b/hw/yagl_backends/egl_onscreen/yagl_egl_onscreen_surface.c
@@ -64,7 +64,9 @@ static void yagl_egl_onscreen_surface_invalidate(struct yagl_eglb_surface *sfc,
     if (((osfc->ws_sfc->base.width != ws_sfc->base.width) ||
          (osfc->ws_sfc->base.height != ws_sfc->base.height)) &&
          osfc->rb) {
+        yagl_ensure_ctx();
         egl_onscreen->gles_driver->DeleteRenderbuffers(1, &osfc->rb);
+        yagl_unensure_ctx();
         osfc->rb = 0;
     }
 
diff --git a/hw/yagl_drivers/gles_onscreen/yagl_gles_onscreen.c b/hw/yagl_drivers/gles_onscreen/yagl_gles_onscreen.c
index 24c251c7bf..c747c787c5 100644
--- a/hw/yagl_drivers/gles_onscreen/yagl_gles_onscreen.c
+++ b/hw/yagl_drivers/gles_onscreen/yagl_gles_onscreen.c
@@ -69,7 +69,7 @@ static void YAGL_GLES_APIENTRY yagl_gles_onscreen_DeleteFramebuffers(GLsizei n,
 
     for (i = 0; i < n; ++i) {
         if (framebuffers[i] != egl_onscreen_ts->ctx->fb) {
-            egl_onscreen_ts->gles_driver->DeleteBuffers(1, &framebuffers[i]);
+            egl_onscreen_ts->gles_driver->DeleteFramebuffers(1, &framebuffers[i]);
         }
     }
 }
-- 
2.34.1