diff options
author | Benjamin Peterson <benjamin@python.org> | 2016-09-19 01:00:25 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2016-09-19 01:00:25 (GMT) |
commit | 9ac11a752a19c3b8607582a3d5ccb615c467124b (patch) | |
tree | fbc0b8a54aed12fcbbfb7e4c11c8d8d1e4ca14dc /Parser/pgen.c | |
parent | 254ad58c0790f3bcf4ca510ba0e8a7c0f1546301 (diff) | |
download | cpython-9ac11a752a19c3b8607582a3d5ccb615c467124b.zip cpython-9ac11a752a19c3b8607582a3d5ccb615c467124b.tar.gz cpython-9ac11a752a19c3b8607582a3d5ccb615c467124b.tar.bz2 |
properly free memory in pgen
Diffstat (limited to 'Parser/pgen.c')
-rw-r--r-- | Parser/pgen.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Parser/pgen.c b/Parser/pgen.c index be35e02..6451a1d 100644 --- a/Parser/pgen.c +++ b/Parser/pgen.c @@ -117,6 +117,16 @@ newnfagrammar(void) return gr; } +static void +freenfagrammar(nfagrammar *gr) +{ + for (int i = 0; i < gr->gr_nnfas; i++) { + PyObject_FREE(gr->gr_nfa[i]->nf_state); + } + PyObject_FREE(gr->gr_nfa); + PyObject_FREE(gr); +} + static nfa * addnfa(nfagrammar *gr, char *name) { @@ -488,7 +498,11 @@ makedfa(nfagrammar *gr, nfa *nf, dfa *d) convert(d, xx_nstates, xx_state); - /* XXX cleanup */ + for (int i = 0; i < xx_nstates; i++) { + for (int j = 0; j < xx_state[i].ss_narcs; j++) + delbitset(xx_state[i].ss_arc[j].sa_bitset); + PyObject_FREE(xx_state[i].ss_arc); + } PyObject_FREE(xx_state); } @@ -669,7 +683,7 @@ pgen(node *n) g = maketables(gr); translatelabels(g); addfirstsets(g); - PyObject_FREE(gr); + freenfagrammar(gr); return g; } |