[Piglit] [PATCH 2/4] util: Add utilities to handle shader_test files
Antia Puentes
apuentes at igalia.com
Thu Aug 9 11:19:31 UTC 2018
Hi Alejandro,
On 20/07/18 17:16, Alejandro PiƱeiro wrote:
> +
> +bool
> +piglit_load_source_from_shader_test(const char *filename,
> + GLenum shader_type,
> + bool spirv,
> + char **output_source,
> + unsigned *output_source_size)
> +{
> + char group_name[4096];
> + char *source = NULL;
> + unsigned text_size;
> + char *line = NULL;
> + char *first_line = NULL;
> +
> + group_name_for_stage(shader_type, spirv, group_name);
> +
> + char *text = piglit_load_text_file(filename, &text_size);
There is a memory leak, you forgot to free "text" before returning.
> + line = text;
> +
> + if (line == NULL) {
> + fprintf(stderr, "Could not read file \"%s\"\n", filename);
> + return false;
> + }
> +
> + while (line[0] != '\0') {
> + if (line[0] == '[' && first_line != NULL) {
> + break;
> + }
> +
> + if (line[0] == '[' && first_line == NULL) {
> + if (parse_str(line, group_name, NULL)) {
> + first_line = strchrnul(line, '\n');
> + if (first_line[0] != '\0')
> + first_line++;
> + }
> + }
> +
> + line = strchrnul(line, '\n');
> + if (line[0] != '\0')
> + line++;
> + }
> +
> + if (first_line == NULL) {
> + fprintf(stderr, "Could not find groupname \"%s\" on file \"%s\"\n",
> + group_name, filename);
> + return false;
> + }
> +
> + 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_size)
> + *output_source_size = text_size;
> +
> + return true;
> +}
>
Regards.
More information about the Piglit
mailing list