diff options
Diffstat (limited to '')
-rw-r--r-- | src/mds-kbdc/mds-kbdc.c | 3 | ||||
-rw-r--r-- | src/mds-kbdc/tree.c | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/mds-kbdc/mds-kbdc.c b/src/mds-kbdc/mds-kbdc.c index d7427d2..fccd1df 100644 --- a/src/mds-kbdc/mds-kbdc.c +++ b/src/mds-kbdc/mds-kbdc.c @@ -57,9 +57,10 @@ int main(int argc_, char** argv_) } mds_kbdc_parse_error_free_all(parse_errors); if (fatal) - return 1; + return mds_kbdc_tree_free(tree), 1; } + mds_kbdc_tree_free(tree); return 0; pfail: diff --git a/src/mds-kbdc/tree.c b/src/mds-kbdc/tree.c index 600bf2a..99fa223 100644 --- a/src/mds-kbdc/tree.c +++ b/src/mds-kbdc/tree.c @@ -63,6 +63,9 @@ static void mds_kbdc_tree_destroy_(mds_kbdc_tree_t* restrict this, int recursive #define xfree(t, v) (free(V(t, v)), V(t, v) = NULL) #define xdestroy(t, v) (recursive ? (mds_kbdc_tree_destroy_(V(t, v), 1), xfree(t, v)) : (V(t, v) = NULL)) + mds_kbdc_tree_t* prev = NULL; + mds_kbdc_tree_t* first = this; + again: if (this == NULL) return; @@ -149,7 +152,10 @@ static void mds_kbdc_tree_destroy_(mds_kbdc_tree_t* restrict this, int recursive break; } + prev = this; this = this->next; + if (prev != first) + free(prev); goto again; #undef xdestroy |