aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/compiler/glsl/blob.h11
-rw-r--r--src/compiler/glsl/shader_cache.cpp2
-rw-r--r--src/compiler/glsl/tests/blob_test.c8
-rw-r--r--src/mesa/state_tracker/st_shader_cache.c2
4 files changed, 17 insertions, 6 deletions
diff --git a/src/compiler/glsl/blob.h b/src/compiler/glsl/blob.h
index 9de12e6eb82..940c81e13b4 100644
--- a/src/compiler/glsl/blob.h
+++ b/src/compiler/glsl/blob.h
@@ -27,6 +27,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
@@ -80,6 +81,16 @@ struct blob *
blob_create(void);
/**
+ * Destroy a blob and free its memory.
+ */
+static inline void
+blob_destroy(struct blob *blob)
+{
+ free(blob->data);
+ free(blob);
+}
+
+/**
* Add some unstructured, fixed-size data to a blob.
*
* \return True unless allocation failed.
diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index ea1bc01f028..f5e6a22bb9e 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -1273,7 +1273,7 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
disk_cache_put(cache, prog->data->sha1, metadata->data, metadata->size);
- free(metadata);
+ blob_destroy(metadata);
if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
_mesa_sha1_format(sha1_buf, prog->data->sha1);
diff --git a/src/compiler/glsl/tests/blob_test.c b/src/compiler/glsl/tests/blob_test.c
index 01b5ef0b2f0..df0e91af353 100644
--- a/src/compiler/glsl/tests/blob_test.c
+++ b/src/compiler/glsl/tests/blob_test.c
@@ -184,7 +184,7 @@ test_write_and_read_functions (void)
"read_consumes_all_bytes");
expect_equal(false, reader.overrun, "read_does_not_overrun");
- free(blob);
+ blob_destroy(blob);
}
/* Test that data values are written and read with proper alignment. */
@@ -242,7 +242,7 @@ test_alignment(void)
"aligned read of intptr_t");
}
- free(blob);
+ blob_destroy(blob);
}
/* Test that we detect overrun. */
@@ -264,7 +264,7 @@ test_overrun(void)
expect_equal(0, blob_read_uint32(&reader), "read at overrun");
expect_equal(true, reader.overrun, "overrun flag set");
- free(blob);
+ blob_destroy(blob);
}
/* Test that we can read and write some large objects, (exercising the code in
@@ -308,7 +308,7 @@ test_big_objects(void)
expect_equal(false, reader.overrun,
"overrun flag not set reading large objects");
- free(blob);
+ blob_destroy(blob);
ralloc_free(ctx);
}
diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
index e8c7289ec6d..1a11f1135d7 100644
--- a/src/mesa/state_tracker/st_shader_cache.c
+++ b/src/mesa/state_tracker/st_shader_cache.c
@@ -135,7 +135,7 @@ st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
_mesa_shader_stage_to_string(prog->info.stage), sha1_buf);
}
- free(blob);
+ blob_destroy(blob);
}
static void