summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Worth <[email protected]>2010-06-23 13:34:05 -0700
committerCarl Worth <[email protected]>2010-06-23 16:18:13 -0700
commitbe83eb8671e7789cbe5ca1fc8d3f5d133e2e7014 (patch)
treeea2f0be29d73120d1189846279d7713ec883fd6d
parent4b2d32b5b5864869419a88d194b740bc0ec211e8 (diff)
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.
-rw-r--r--main.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/main.cpp b/main.cpp
index 17f25d741e4..78169d257d0 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;
}