From be83eb8671e7789cbe5ca1fc8d3f5d133e2e7014 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 23 Jun 2010 13:34:05 -0700 Subject: glsl2 main: Use talloc to allocate whole_program struct. This way, whole_program can be our top-level talloc context object, allowing us to free the lot with a single talloc_free in the end. --- main.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index 17f25d7..78169d2 100644 --- a/main.cpp +++ b/main.cpp @@ -200,20 +200,21 @@ main(int argc, char **argv) if (argc <= optind) usage_fail(argv[0]); - struct glsl_program whole_program; - memset(&whole_program, 0, sizeof(whole_program)); + struct glsl_program *whole_program; + + whole_program = talloc_zero (NULL, struct glsl_program); + assert(whole_program != NULL); for (/* empty */; argc > optind; optind++) { - whole_program.Shaders = (struct glsl_shader **) - realloc(whole_program.Shaders, - sizeof(struct glsl_shader *) * (whole_program.NumShaders + 1)); - assert(whole_program.Shaders != NULL); + whole_program->Shaders = (struct glsl_shader **) + realloc(whole_program->Shaders, + sizeof(struct glsl_shader *) * (whole_program->NumShaders + 1)); + assert(whole_program->Shaders != NULL); - /* talloc context should probably be whole_program */ - struct glsl_shader *shader = talloc_zero(NULL, glsl_shader); + struct glsl_shader *shader = talloc_zero(whole_program, glsl_shader); - whole_program.Shaders[whole_program.NumShaders] = shader; - whole_program.NumShaders++; + whole_program->Shaders[whole_program->NumShaders] = shader; + whole_program->NumShaders++; const unsigned len = strlen(argv[optind]); if (len < 6) @@ -245,9 +246,11 @@ main(int argc, char **argv) } if ((status == EXIT_SUCCESS) && do_link) { - link_shaders(&whole_program); - status = (whole_program.LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE; + link_shaders(whole_program); + status = (whole_program->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE; } + talloc_free(whole_program); + return status; } -- cgit v1.2.3