[Mesa-dev] [PATCH 14/68] i965: stop leaking memory on cache restore

Timothy Arceri timothy.arceri at collabora.com
Wed Jun 1 06:22:55 UTC 2016


Also replace some fallbacks with asserts.
---
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 39 ++++++++++------------------
 1 file changed, 13 insertions(+), 26 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index 3e5314d..c565e5a 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -56,7 +56,6 @@ upload_cached_program(struct brw_context *brw)
    size_t vs_prog_data_size, wm_prog_data_size;
    intptr_t parameter_values_base;
    intptr_t uniform_data_slots_base;
-   void *local = ralloc_context(NULL);
    uint32_t nr_params, nr_pull_params;
 
    cache = brw->ctx.Cache;
@@ -108,10 +107,9 @@ upload_cached_program(struct brw_context *brw)
    uniform_data_slots_base = blob_read_intptr(&binary);
 
    nr_params = blob_read_uint32(&binary);
-   if (nr_params != prog_data->nr_params)
-      goto FAIL;
+   assert(nr_params == prog_data->nr_params);
 
-   prog_data->param = rzalloc_array(local, const gl_constant_value *,
+   prog_data->param = rzalloc_array(NULL, const gl_constant_value *,
                                     nr_params);
    printf("Allocating %d prog_data->params (%p)\n",
           prog_data->nr_params, prog_data->param);
@@ -132,15 +130,16 @@ upload_cached_program(struct brw_context *brw)
          prog_data->param[i] = prog->UniformDataSlots + u_offset;
       } else {
          printf("Error: Failed to fixup vs pointer value %p\n", (void *) param);
+         ralloc_free(prog_data->param);
+         ralloc_free(prog_data->image_param);
          goto FAIL;
       }
    }
 
    nr_pull_params = blob_read_uint32(&binary);
-   if (nr_pull_params != prog_data->nr_pull_params)
-      goto FAIL;
+   assert(nr_pull_params == prog_data->nr_pull_params);
 
-   prog_data->pull_param = rzalloc_array(local, const gl_constant_value *,
+   prog_data->pull_param = rzalloc_array(NULL, const gl_constant_value *,
                                          nr_pull_params);
 
 
@@ -164,8 +163,7 @@ upload_cached_program(struct brw_context *brw)
 
    /* Read WM program_data from blob and fixup params pointers. */
    wm_prog_data_size = blob_read_uint32(&binary);
-   if (wm_prog_data_size != sizeof *wm_prog_data)
-      goto FAIL;
+   assert(wm_prog_data_size == sizeof *wm_prog_data);
 
    wm_prog_data = blob_read_bytes(&binary, wm_prog_data_size);
    prog_data = &wm_prog_data->base;
@@ -173,10 +171,9 @@ upload_cached_program(struct brw_context *brw)
    parameter_values_base = blob_read_intptr(&binary);
 
    nr_params = blob_read_uint32(&binary);
-   if (nr_params != prog_data->nr_params)
-      goto FAIL;
+   assert(nr_params == prog_data->nr_params);
 
-   prog_data->param = rzalloc_array(local, const gl_constant_value *,
+   prog_data->param = rzalloc_array(NULL, const gl_constant_value *,
                                     nr_params);
    printf("Allocating %d prog_data->params (%p)\n",
           prog_data->nr_params, prog_data->param);
@@ -197,15 +194,16 @@ upload_cached_program(struct brw_context *brw)
          prog_data->param[i] = prog->UniformDataSlots + u_offset;
       } else {
          printf("Error: Failed to fixup fs pointer value %p\n", (void *) param);
+         ralloc_free(prog_data->param);
+         ralloc_free(prog_data->image_param);
          goto FAIL;
       }
    }
 
    nr_pull_params = blob_read_uint32(&binary);
-   if (nr_pull_params != prog_data->nr_pull_params)
-      goto FAIL;
+   assert(nr_pull_params == prog_data->nr_pull_params);
 
-   prog_data->pull_param = rzalloc_array(local, const gl_constant_value *,
+   prog_data->pull_param = rzalloc_array(NULL, const gl_constant_value *,
                                          nr_pull_params);
 
 
@@ -231,23 +229,12 @@ upload_cached_program(struct brw_context *brw)
    printf ("%s: Successfully read every byte written!\n", __FUNCTION__);
    prog->program_written_to_cache = true;
 
-/* FIXME: I'm currently leaking anything allocated off of this local
- * context. What we really want here is a context that lives across both
- * upload_cached_program and write_cached program. To implement this, Ken
- * suggests rewriting brw_state_upload.c:brw_upload_state() to pull the code
- * called for the common atoms out of the loop, and then explicitly call these
- * caching functions around those, (rather than hooking into the atoms to call
- * our cache functions).
-
-   ralloc_free(local);
-*/
    free(buffer);
    return;
 
 FAIL:
    /* Fall back and compile from source here. */
    prog->program_written_to_cache = false;
-   local = NULL;
    printf("FIXME: May need to fallback to compile from source here...\n");
    free(buffer);
 }
-- 
2.5.5



More information about the mesa-dev mailing list