summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-06-18 17:37:02 -0700
committerCarl Worth <cworth@cworth.org>2010-06-23 19:00:42 -0700
commita9696e79fb3afc6a4724bd16ee1ccdfebebfd0fd (patch)
treed2f476b08f00adab2317cfe42e6eacd1ddd98463 /main.cpp
parent007efe50fdd87c8ceb2a700b6105ce6f00ba56e8 (diff)
main: Close memory leak of shader string from load_text_file.
Could have just added a call to free() to main, but since we're using talloc everywhere else, we might as well just use it here too. So pass a new 'ctx' argument to load_text_file. This removes a single memory leak from all invocations of the standalone glsl compiler.
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/main.cpp b/main.cpp
index dcd4b8f672..dfed4a30e8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -36,9 +36,9 @@
#include "ir_print_visitor.h"
#include "program.h"
-
+/* Returned string will have 'ctx' as its talloc owner. */
static char *
-load_text_file(const char *file_name, size_t *size)
+load_text_file(void *ctx, const char *file_name, size_t *size)
{
char *text = NULL;
struct stat st;
@@ -51,7 +51,7 @@ load_text_file(const char *file_name, size_t *size)
}
if (fstat(fd, & st) == 0) {
- text = (char *) malloc(st.st_size + 1);
+ text = (char *) talloc_size(ctx, st.st_size + 1);
if (text != NULL) {
do {
ssize_t bytes = read(fd, text + total_read,
@@ -229,7 +229,8 @@ main(int argc, char **argv)
else
usage_fail(argv[0]);
- shader->Source = load_text_file(argv[optind], &shader->SourceLen);
+ shader->Source = load_text_file(whole_program,
+ argv[optind], &shader->SourceLen);
if (shader->Source == NULL) {
printf("File \"%s\" does not exist.\n", argv[optind]);
exit(EXIT_FAILURE);