From 02d14ec15cf5a41aca3208e8d5bce7dab8dd1fe4 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 4 Apr 2011 14:42:36 +0100 Subject: [PATCH] offscreen: Plug a leak in an error path When creating a CoglOffscreen we take a reference on the texture handle, but in case of error we never release it. We should take that reference only on success. http://bugzilla.clutter-project.org/show_bug.cgi?id=2620 --- clutter/cogl/cogl/cogl-framebuffer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clutter/cogl/cogl/cogl-framebuffer.c b/clutter/cogl/cogl/cogl-framebuffer.c index f006407ce..d3f153735 100644 --- a/clutter/cogl/cogl/cogl-framebuffer.c +++ b/clutter/cogl/cogl/cogl-framebuffer.c @@ -862,7 +862,7 @@ _cogl_offscreen_new_to_texture_full (CoglHandle texhandle, _cogl_texture_set_filters (texhandle, GL_NEAREST, GL_NEAREST); offscreen = g_new0 (CoglOffscreen, 1); - offscreen->texture = cogl_handle_ref (texhandle); + offscreen->texture = texhandle; if ((create_flags & COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL)) fbo_created = try_creating_fbo (offscreen, 0, &data); @@ -898,8 +898,12 @@ _cogl_offscreen_new_to_texture_full (CoglHandle texhandle, data.level_width, data.level_height); + /* take a reference on the texture */ + cogl_handle_ref (offscreen->texture); + ret = _cogl_offscreen_object_new (offscreen); _cogl_texture_associate_framebuffer (texhandle, COGL_FRAMEBUFFER (ret)); + return ret; } else @@ -907,6 +911,7 @@ _cogl_offscreen_new_to_texture_full (CoglHandle texhandle, g_free (offscreen); /* XXX: This API should probably have been defined to take a GError */ g_warning ("%s: Failed to create an OpenGL framebuffer", G_STRLOC); + return COGL_INVALID_HANDLE; } }