From 274bc8b0c13e10b61af90e9de736fefb69f92351 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 27 Jan 2017 17:42:33 -0600 Subject: [PATCH 1/2] Fix indentation. --- link-grammar/api.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/link-grammar/api.c b/link-grammar/api.c index a6c990ade3..73bd234b6a 100644 --- a/link-grammar/api.c +++ b/link-grammar/api.c @@ -455,32 +455,31 @@ static Linkage linkage_array_new(int num_to_alloc) void free_linkage(Linkage linkage) { - size_t j; - - exfree((void *) linkage->word, sizeof(const char *) * linkage->num_words); - exfree(linkage->chosen_disjuncts, linkage->num_words * sizeof(Disjunct *)); - free(linkage->link_array); + exfree((void *) linkage->word, sizeof(const char *) * linkage->num_words); + exfree(linkage->chosen_disjuncts, linkage->num_words * sizeof(Disjunct *)); + free(linkage->link_array); - /* Q: Why isn't this in a string set ?? A: Because there is no - * string-set handy when we compute this. */ - if (linkage->disjunct_list_str) + /* Q: Why isn't this in a string set ?? A: Because there is no + * string-set handy when we compute this. */ + if (linkage->disjunct_list_str) + { + size_t j; + for (j=0; jnum_words; j++) { - for (j=0; jnum_words; j++) - { - if (linkage->disjunct_list_str[j]) - free(linkage->disjunct_list_str[j]); - } - free(linkage->disjunct_list_str); + if (linkage->disjunct_list_str[j]) + free(linkage->disjunct_list_str[j]); } + free(linkage->disjunct_list_str); + } #ifdef USE_CORPUS - lg_sense_delete(linkage); + lg_sense_delete(linkage); #endif - linkage_free_pp_info(linkage); + linkage_free_pp_info(linkage); - /* XXX FIXME */ - free(linkage->wg_path); - free(linkage->wg_path_display); + /* XXX FIXME */ + free(linkage->wg_path); + free(linkage->wg_path_display); } static void free_linkages(Sentence sent) From 7f7256707c875d99d8fcba6c0d505eacfb3c5258 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 27 Jan 2017 17:54:40 -0600 Subject: [PATCH 2/2] Fix memleak. --- link-grammar/api.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/link-grammar/api.c b/link-grammar/api.c index 73bd234b6a..4437ec1091 100644 --- a/link-grammar/api.c +++ b/link-grammar/api.c @@ -1340,6 +1340,9 @@ static void process_linkages(Sentence sent, bool overflowed, Parse_Options opts) } } + /* The last one was alloced, but never actually used. Free it. */ + if (!need_init) free_linkage(&sent->lnkages[in]); + /* The remainder of the array is garbage; we never filled it in. * So just pretend that it's shorter than it is */ sent->num_linkages_alloced = sent->num_valid_linkages;