diff options
author | Alex Rozenman <rozenman@gmail.com> | 2009-07-24 21:04:16 +0300 |
---|---|---|
committer | Alex Rozenman <rozenman@gmail.com> | 2009-07-24 21:08:46 +0300 |
commit | 1e20ad112fc43f3d6adb3cc26be69ebffb14e9f6 (patch) | |
tree | 1ac6059b6c645e57c969840788aca549807976ef /src | |
parent | ac9b0e954b1d3aed514a3bbd363da1514202af0f (diff) | |
download | bison-1e20ad112fc43f3d6adb3cc26be69ebffb14e9f6.tar.gz |
Fix some memory leaks.
* src/named-ref.c: Add a pointer check (named_ref_free).
* src/scan-code.l: New function (variant_table_free). Called in
code_scanner_free.
* src/symlist.c: Call to named_ref_free (symbol_list_free).
Diffstat (limited to 'src')
-rw-r--r-- | src/named-ref.c | 3 | ||||
-rw-r--r-- | src/scan-code.l | 11 | ||||
-rw-r--r-- | src/symlist.c | 9 |
3 files changed, 21 insertions, 2 deletions
diff --git a/src/named-ref.c b/src/named-ref.c index 4388acba..41d9dc17 100644 --- a/src/named-ref.c +++ b/src/named-ref.c @@ -36,6 +36,7 @@ named_ref_new (uniqstr id, location loc) void named_ref_free (named_ref *r) { - free (r); + if (r) + free (r); } diff --git a/src/scan-code.l b/src/scan-code.l index 47cde77e..d57eafa3 100644 --- a/src/scan-code.l +++ b/src/scan-code.l @@ -350,6 +350,15 @@ variant_table_grow () return &variant_table[variant_count - 1]; } +static void +variant_table_free () +{ + if (variant_table) + free (variant_table); + variant_table = 0; + variant_table_size = variant_count = 0; +} + static char * find_prefix_end (const char *prefix, char *begin, char *end) { @@ -865,6 +874,8 @@ void code_scanner_free (void) { obstack_free (&obstack_for_string, 0); + variant_table_free (); + /* Reclaim Flex's buffers. */ yylex_destroy (); } diff --git a/src/symlist.c b/src/symlist.c index b3500d2d..1ffad2b6 100644 --- a/src/symlist.c +++ b/src/symlist.c @@ -146,7 +146,14 @@ symbol_list_prepend (symbol_list *list, symbol_list *node) void symbol_list_free (symbol_list *list) { - LIST_FREE (symbol_list, list); + symbol_list *node, *next; + for (node = list; node; node = next) + { + next = node->next; + if (node->named_ref) + named_ref_free (node->named_ref); + free (node); + } } |