st/mesa: Initialize textures array in st_framebuffer_validate

And just reference pipe_resources to it in the validate callbacks.

Avoids pipe_resource leaks when st_framebuffer_validate ends up calling
the validate callback multiple times, e.g. when a window is resized.

v2:
* Use generic stable tag instead of Fixes: tag, since the problem could
  already happen before the commit referenced in v1 (Thomas Hellstrom)
* Use memset to initialize the array on the stack instead of allocating
  the array with os_calloc.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
This commit is contained in:
Michel Dänzer 2017-10-16 16:35:18 +02:00 committed by Michel Dänzer
parent 47273d7312
commit 7561da367b
6 changed files with 7 additions and 12 deletions

View file

@ -99,10 +99,8 @@ dri_st_framebuffer_validate(struct st_context_iface *stctx,
return TRUE;
/* Set the window-system buffers for the state tracker. */
for (i = 0; i < count; i++) {
out[i] = NULL;
for (i = 0; i < count; i++)
pipe_resource_reference(&out[i], textures[statts[i]]);
}
return TRUE;
}

View file

@ -245,10 +245,8 @@ xmesa_st_framebuffer_validate(struct st_context_iface *stctx,
}
}
for (i = 0; i < count; i++) {
out[i] = NULL;
for (i = 0; i < count; i++)
pipe_resource_reference(&out[i], xstfb->textures[statts[i]]);
}
return TRUE;
}

View file

@ -193,10 +193,8 @@ hgl_st_framebuffer_validate(struct st_context_iface *stctxi,
//}
}
for (i = 0; i < count; i++) {
out[i] = NULL;
for (i = 0; i < count; i++)
pipe_resource_reference(&out[i], buffer->textures[statts[i]]);
}
return TRUE;
}

View file

@ -432,6 +432,7 @@ osmesa_st_framebuffer_validate(struct st_context_iface *stctx,
templat.format = format;
templat.bind = bind;
pipe_resource_reference(&out[i], NULL);
out[i] = osbuffer->textures[statts[i]] =
screen->resource_create(screen, &templat);
}

View file

@ -161,10 +161,8 @@ stw_st_framebuffer_validate(struct st_context_iface *stctx,
stwfb->fb->must_resize = FALSE;
}
for (i = 0; i < count; i++) {
out[i] = NULL;
for (i = 0; i < count; i++)
pipe_resource_reference(&out[i], stwfb->textures[statts[i]]);
}
stw_framebuffer_unlock(stwfb->fb);

View file

@ -190,6 +190,8 @@ st_framebuffer_validate(struct st_framebuffer *stfb,
if (stfb->iface_stamp == new_stamp)
return;
memset(textures, 0, stfb->num_statts * sizeof(textures[0]));
/* validate the fb */
do {
if (!stfb->iface->validate(&st->iface, stfb->iface, stfb->statts,