From e694ea09f57cdce557a7424401e68b37e0e80fa7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 1 Dec 2012 22:38:36 +0100 Subject: [PATCH] r300g: fix memory leaks in texture_create error paths --- src/gallium/drivers/r300/r300_texture.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 7f74538deea..33333ca51b5 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -953,15 +953,16 @@ r300_texture_create_object(struct r300_screen *rscreen, struct pb_buffer *buffer) { struct radeon_winsys *rws = rscreen->rws; - struct r300_resource *tex = CALLOC_STRUCT(r300_resource); - if (!tex) { - if (buffer) - pb_reference(&buffer, NULL); - return NULL; + struct r300_resource *tex = NULL; + + if (base->nr_samples > 1) { + goto fail; } - if (base->nr_samples > 1) - return NULL; + tex = CALLOC_STRUCT(r300_resource); + if (!tex) { + goto fail; + } pipe_reference_init(&tex->b.b.reference, 1); tex->b.b.screen = &rscreen->screen; @@ -985,8 +986,7 @@ r300_texture_create_object(struct r300_screen *rscreen, base->bind, tex->domain); if (!tex->buf) { - FREE(tex); - return NULL; + goto fail; } } @@ -998,6 +998,12 @@ r300_texture_create_object(struct r300_screen *rscreen, tex->tex.stride_in_bytes[0]); return tex; + +fail: + FREE(tex); + if (buffer) + pb_reference(&buffer, NULL); + return NULL; } /* Create a new texture. */ -- 2.30.2