[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/5] fix a memory leak
From: |
Akim Demaille |
Subject: |
[PATCH 3/5] fix a memory leak |
Date: |
Thu, 30 May 2013 10:50:17 +0200 |
* src/print-xml.c (num_escape_bufs): New.
(print_xml): Be sure to release all the escape_bufs.
---
src/print-xml.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/print-xml.c b/src/print-xml.c
index a3ef151..e5c25c5 100644
--- a/src/print-xml.c
+++ b/src/print-xml.c
@@ -45,7 +45,8 @@ struct escape_buf
char *ptr;
size_t size;
};
-static struct escape_buf escape_bufs[3];
+enum { num_escape_bufs = 3 };
+static struct escape_buf escape_bufs[num_escape_bufs];
/*--------------------------------.
@@ -496,7 +497,6 @@ xml_escape (char const *str)
void
print_xml (void)
{
- state_number i;
int level = 0;
FILE *out = xfopen (spec_xml_file, "w");
@@ -522,8 +522,11 @@ print_xml (void)
/* print automaton */
fputc ('\n', out);
xml_puts (out, level + 1, "<automaton>");
- for (i = 0; i < nstates; i++)
- print_state (out, level + 2, states[i]);
+ {
+ state_number i;
+ for (i = 0; i < nstates; i++)
+ print_state (out, level + 2, states[i]);
+ }
xml_puts (out, level + 1, "</automaton>");
bitset_free (no_reduce_set);
@@ -531,8 +534,11 @@ print_xml (void)
xml_puts (out, 0, "</bison-xml-report>");
- free (escape_bufs[0].ptr);
- free (escape_bufs[1].ptr);
+ {
+ int i;
+ for (i = 0; i < num_escape_bufs; ++i)
+ free (escape_bufs[i].ptr);
+ }
xfclose (out);
}
--
1.8.2.3
- [PATCH 0/5] {master} minor fixes, Akim Demaille, 2013/05/30
- [PATCH 3/5] fix a memory leak,
Akim Demaille <=
- [PATCH 4/5] build: locally disable new GCC warnings that fail on Flex generated code, Akim Demaille, 2013/05/30
- [PATCH 1/5] build: be sure to include config.h first in the generated parser, Akim Demaille, 2013/05/30
- [PATCH 5/5] xml: use %empty in the text output, Akim Demaille, 2013/05/30
- [PATCH 2/5] regen, Akim Demaille, 2013/05/30
- Re: [PATCH 0/5] {master} minor fixes, Akim Demaille, 2013/05/30