OSDN Git Service

st/mesa: Initialize textures array in st_framebuffer_validate
authorMichel Dänzer <michel.daenzer@amd.com>
Mon, 16 Oct 2017 14:35:18 +0000 (16:35 +0200)
committerMichel Dänzer <michel@daenzer.net>
Wed, 18 Oct 2017 16:28:00 +0000 (18:28 +0200)
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>
src/gallium/state_trackers/dri/dri_drawable.c
src/gallium/state_trackers/glx/xlib/xm_st.c
src/gallium/state_trackers/hgl/hgl.c
src/gallium/state_trackers/osmesa/osmesa.c
src/gallium/state_trackers/wgl/stw_st.c
src/mesa/state_tracker/st_manager.c

index 75a8197..d586b75 100644 (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;
 }
index 0c42e65..946b5dc 100644 (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;
 }
index 1b70281..bbc477a 100644 (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;
 }
index 2f9558d..44a0cc4 100644 (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);
    }
index 5e165c8..7cf18f0 100644 (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);
 
index aef87ea..eebde62 100644 (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,