summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Engestrom <eric.engestrom@intel.com>2018-08-23 15:18:36 +0100
committerEric Engestrom <eric.engestrom@intel.com>2018-08-23 17:44:17 +0100
commit8d6f9c376a2b7f917172b402edf5ddea1f3a4b04 (patch)
tree57a60a5f4d3ab4f44d8f19eb4f336f24a2b7896e
parented20063b5ed7b18f742d5d9e1423be2cd4f6ff48 (diff)
util: avoid leaking memory when caller doesn't ask for it
It doesn't happen anywhere right now, but a caller could say it doesn't want the source, only its size, and in that case we would just leak that memory. Let's only actually allocate it when the caller wants it and will take ownership of that memory. Suggested-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> Signed-off-by: Eric Engestrom <eric.engestrom@intel.com> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
-rw-r--r--tests/util/piglit-shader-test.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/tests/util/piglit-shader-test.c b/tests/util/piglit-shader-test.c
index 4802983e5..f11ee8ab5 100644
--- a/tests/util/piglit-shader-test.c
+++ b/tests/util/piglit-shader-test.c
@@ -101,7 +101,6 @@ piglit_load_source_from_shader_test(const char *filename,
unsigned *output_source_size)
{
char group_name[4096];
- char *source = NULL;
unsigned text_size;
char *line = NULL;
char *first_line = NULL;
@@ -142,11 +141,11 @@ piglit_load_source_from_shader_test(const char *filename,
}
text_size = line - first_line + 1;
- source = malloc(sizeof(char*) * text_size);
- snprintf(source, line - first_line + 1, "%s", first_line);
- if (output_source)
- *output_source = source;
+ if (output_source) {
+ *output_source = malloc(sizeof(char*) * text_size);
+ snprintf(*output_source, line - first_line + 1, "%s", first_line);
+ }
if (output_source_size)
*output_source_size = text_size;