[Mesa-dev] [PATCH 6/6] st/mesa: handle out-of-memory when resizing sampler views array
Nicolai Hähnle
nhaehnle at gmail.com
Fri Oct 6 20:38:16 UTC 2017
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
---
src/mesa/state_tracker/st_sampler_view.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/mesa/state_tracker/st_sampler_view.c b/src/mesa/state_tracker/st_sampler_view.c
index 638fac671b2..de104355c04 100644
--- a/src/mesa/state_tracker/st_sampler_view.c
+++ b/src/mesa/state_tracker/st_sampler_view.c
@@ -69,21 +69,27 @@ st_texture_get_sampler_view(struct st_context *st,
free = sv;
}
}
/* Couldn't find a slot for our context, create a new one */
if (!free) {
/* Haven't even found a free one, resize the array */
unsigned new_size = (stObj->num_sampler_views + 1) *
sizeof(struct st_sampler_view);
- stObj->sampler_views = realloc(stObj->sampler_views, new_size);
+ struct st_sampler_view *new_sampler_views = realloc(stObj->sampler_views, new_size);
+ if (!new_sampler_views) {
+ _mesa_error(st->ctx, GL_OUT_OF_MEMORY, "sampler views array");
+ return NULL;
+ }
+
+ stObj->sampler_views = new_sampler_views;
free = &stObj->sampler_views[stObj->num_sampler_views++];
free->view = NULL;
}
assert(free->view == NULL);
return free;
}
@@ -457,20 +463,25 @@ struct pipe_sampler_view *
st_get_texture_sampler_view_from_stobj(struct st_context *st,
struct st_texture_object *stObj,
const struct gl_sampler_object *samp,
bool glsl130_or_later)
{
struct st_sampler_view *sv;
struct pipe_sampler_view *view;
mtx_lock(&stObj->validate_mutex);
sv = st_texture_get_sampler_view(st, stObj);
+ if (!sv) {
+ mtx_unlock(&stObj->validate_mutex);
+ return NULL;
+ }
+
view = sv->view;
if (view &&
sv->glsl130_or_later == glsl130_or_later &&
sv->sRGBDecode == samp->sRGBDecode) {
/* Debug check: make sure that the sampler view's parameters are
* what they're supposed to be.
*/
MAYBE_UNUSED struct pipe_sampler_view *view = sv->view;
assert(stObj->pt == view->texture);
@@ -510,20 +521,24 @@ st_get_buffer_sampler_view_from_stobj(struct st_context *st,
{
struct st_sampler_view *sv;
struct st_buffer_object *stBuf =
st_buffer_object(stObj->base.BufferObject);
if (!stBuf || !stBuf->buffer)
return NULL;
mtx_lock(&stObj->validate_mutex);
sv = st_texture_get_sampler_view(st, stObj);
+ if (!sv) {
+ mtx_unlock(&stObj->validate_mutex);
+ return NULL;
+ }
struct pipe_resource *buf = stBuf->buffer;
struct pipe_sampler_view *view = sv->view;
if (view && view->texture == buf) {
/* Debug check: make sure that the sampler view's parameters are
* what they're supposed to be.
*/
assert(st_mesa_format_to_pipe_format(st, stObj->base._BufferObjectFormat)
== view->format);
--
2.11.0
More information about the mesa-dev
mailing list