From: Kenneth Graunke Date: Fri, 28 Jun 2019 00:16:20 +0000 (-0700) Subject: iris: Don't leak resources in iris_create_surface for incomplete FBOs X-Git-Tag: upstream/19.3.0~5028 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=847ef8ee4f0889be651f12ad5bbc7e43a177431a;p=platform%2Fupstream%2Fmesa.git iris: Don't leak resources in iris_create_surface for incomplete FBOs We were failing to pipe_resource_unreference on the failure path due to a non-renderable format. Instead of fixing this, just move the checks earlier, before we even bother with refcounting or calloc. --- diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index e09a3dd..cc59fda 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -1874,23 +1874,6 @@ iris_create_surface(struct pipe_context *ctx, struct iris_context *ice = (struct iris_context *) ctx; struct iris_screen *screen = (struct iris_screen *)ctx->screen; const struct gen_device_info *devinfo = &screen->devinfo; - struct iris_surface *surf = calloc(1, sizeof(struct iris_surface)); - struct pipe_surface *psurf = &surf->base; - struct iris_resource *res = (struct iris_resource *) tex; - - if (!surf) - return NULL; - - pipe_reference_init(&psurf->reference, 1); - pipe_resource_reference(&psurf->texture, tex); - psurf->context = ctx; - psurf->format = tmpl->format; - psurf->width = tex->width0; - psurf->height = tex->height0; - psurf->texture = tex; - psurf->u.tex.first_layer = tmpl->u.tex.first_layer; - psurf->u.tex.last_layer = tmpl->u.tex.last_layer; - psurf->u.tex.level = tmpl->u.tex.level; isl_surf_usage_flags_t usage = 0; if (tmpl->writable) @@ -1901,7 +1884,7 @@ iris_create_surface(struct pipe_context *ctx, usage = ISL_SURF_USAGE_RENDER_TARGET_BIT; const struct iris_format_info fmt = - iris_format_for_usage(devinfo, psurf->format, usage); + iris_format_for_usage(devinfo, tmpl->format, usage); if ((usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) && !isl_format_supports_rendering(devinfo, fmt.fmt)) { @@ -1909,10 +1892,27 @@ iris_create_surface(struct pipe_context *ctx, * hasn't had the opportunity yet. In the meantime, we need to * avoid hitting ISL asserts about unsupported formats below. */ - free(surf); return NULL; } + struct iris_surface *surf = calloc(1, sizeof(struct iris_surface)); + struct pipe_surface *psurf = &surf->base; + struct iris_resource *res = (struct iris_resource *) tex; + + if (!surf) + return NULL; + + pipe_reference_init(&psurf->reference, 1); + pipe_resource_reference(&psurf->texture, tex); + psurf->context = ctx; + psurf->format = tmpl->format; + psurf->width = tex->width0; + psurf->height = tex->height0; + psurf->texture = tex; + psurf->u.tex.first_layer = tmpl->u.tex.first_layer; + psurf->u.tex.last_layer = tmpl->u.tex.last_layer; + psurf->u.tex.level = tmpl->u.tex.level; + struct isl_view *view = &surf->view; *view = (struct isl_view) { .format = fmt.fmt,