Skip to content

Commit

Permalink
Merge pull request #487 from linas/meml
Browse files Browse the repository at this point in the history
fix memleak in the new code.
  • Loading branch information
linas authored Jan 27, 2017
2 parents 3a81954 + 7f72567 commit 3cf0af4
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions link-grammar/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; j<linkage->num_words; j++)
{
for (j=0; j<linkage->num_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)
Expand Down Expand Up @@ -1341,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;
Expand Down

0 comments on commit 3cf0af4

Please sign in to comment.