From 9198e790b71c2c876bd2340d073a3e82b95e9dbd Mon Sep 17 00:00:00 2001 From: Nicolai Hähnle Date: Tue, 16 Jan 2018 14:38:00 +0100 Subject: radeonsi: fix failure paths of r600_texture_transfer_map trans is zero-initialized, but trans->resource is setup immediately so needs to be dereferenced. --- src/gallium/drivers/radeon/r600_texture.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c index 02bbd0bf0d..7158a77c84 100644 --- a/src/gallium/drivers/radeon/r600_texture.c +++ b/src/gallium/drivers/radeon/r600_texture.c @@ -1738,16 +1738,14 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx, if (!si_init_flushed_depth_texture(ctx, &resource, &staging_depth)) { R600_ERR("failed to create temporary texture to hold untiled copy\n"); - FREE(trans); - return NULL; + goto fail_trans; } if (usage & PIPE_TRANSFER_READ) { struct pipe_resource *temp = ctx->screen->resource_create(ctx->screen, &resource); if (!temp) { R600_ERR("failed to create a temporary depth texture\n"); - FREE(trans); - return NULL; + goto fail_trans; } r600_copy_region_with_blit(ctx, temp, 0, 0, 0, 0, texture, level, box); @@ -1765,8 +1763,7 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx, /* XXX: when discard is true, no need to read back from depth texture */ if (!si_init_flushed_depth_texture(ctx, texture, &staging_depth)) { R600_ERR("failed to create temporary texture to hold untiled copy\n"); - FREE(trans); - return NULL; + goto fail_trans; } rctx->blit_decompress_depth(ctx, rtex, staging_depth, @@ -1795,8 +1792,7 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx, staging = (struct r600_texture*)ctx->screen->resource_create(ctx->screen, &resource); if (!staging) { R600_ERR("failed to create temporary texture to hold untiled copy\n"); - FREE(trans); - return NULL; + goto fail_trans; } trans->staging = &staging->resource; @@ -1819,14 +1815,17 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx, buf = &rtex->resource; } - if (!(map = si_buffer_map_sync_with_rings(rctx, buf, usage))) { - r600_resource_reference(&trans->staging, NULL); - FREE(trans); - return NULL; - } + if (!(map = si_buffer_map_sync_with_rings(rctx, buf, usage))) + goto fail_trans; *ptransfer = &trans->b.b; return map + offset; + +fail_trans: + r600_resource_reference(&trans->staging, NULL); + pipe_resource_reference(&trans->b.b.resource, NULL); + FREE(trans); + return NULL; } static void r600_texture_transfer_unmap(struct pipe_context *ctx, -- cgit v1.2.3