summaryrefslogtreecommitdiff
path: root/src/mesa/shader/program_parser.h
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2009-10-27 13:40:18 -0700
committerIan Romanick <ian.d.romanick@intel.com>2009-10-27 17:06:18 -0700
commit93dae6761bc90bbd43b450d2673620ec189b2c7a (patch)
tree034b2c8d4c50ecf5e96e9b8c255421e487c90b88 /src/mesa/shader/program_parser.h
parent8df9587d68752f3369cc1eda1606d3b7c1041ec6 (diff)
ARB prog parser: Fix epic memory leak in lexer / parser interface
Anything that matched IDENTIFIER was strdup'ed and returned to the parser. However, almost every case of IDENTIFIER in the parser just dropped the returned string on the floor. Every swizzle string, every option string, every use of a variable, etc. leaked memory. Create a temporary buffer in the parser state (string_dumpster and dumpster_size). Return strings from the lexer to the parser in the buffer. Grow the buffer as needed. When the parser needs to keep a string (i.e., delcaring a new variable), let it make a copy then. The only leak that valgrind now detects is /occasionally/ the copy of the program string in gl_program::String is leaked. I'm not seeing how. :(
Diffstat (limited to 'src/mesa/shader/program_parser.h')
-rw-r--r--src/mesa/shader/program_parser.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/mesa/shader/program_parser.h b/src/mesa/shader/program_parser.h
index fa47d84565..8d8b4d89bc 100644
--- a/src/mesa/shader/program_parser.h
+++ b/src/mesa/shader/program_parser.h
@@ -38,6 +38,13 @@ enum asm_type {
at_output,
};
+/**
+ * \note
+ * Objects of this type are allocated as the object plus the name of the
+ * symbol. That is, malloc(sizeof(struct asm_symbol) + strlen(name) + 1).
+ * Alternately, asm_symbol::name could be moved to the bottom of the structure
+ * and declared as 'char name[0];'.
+ */
struct asm_symbol {
struct asm_symbol *next; /**< List linkage for freeing. */
const char *name;
@@ -158,6 +165,15 @@ struct asm_parser_state {
/**
+ * Buffer to hold strings transfered from the lexer to the parser
+ */
+ /*@{*/
+ char *string_dumpster; /**< String data transfered. */
+ size_t dumpster_size; /**< Total size, in bytes, of the buffer. */
+ /*@}*/
+
+
+ /**
* Selected limits copied from gl_constants
*
* These are limits from the GL context, but various bits in the program