snowballstem / snowball

Snowball compiler and stemming algorithms
https://snowballstem.org/
BSD 3-Clause "New" or "Revised" License
748 stars 173 forks source link

fix a memleak in snowball compiler #166

Closed jsteemann closed 1 year ago

jsteemann commented 2 years ago

When an output file is used and the name option is not, then the compiler will dynamically allocate value for the name option and never free it. This is not a large problem, because at the end of the compile process the OS will free all allocated memory anyway. However, when using snowball as part of a larger toolchain and then using compile options such as -fsanitize=leak, a memleak in snowball can break the entire build. This exactly what happened to us. We could work around this somehow, but it seems better to fix the leak in the compiler properly.

The same issue was already reported previously by a former colleague of mine in https://github.com/snowballstem/snowball/pull/136, but that PR seemingly was disliked by the snowball maintainers. Trying it again with this PR with a slightly modified solution and hope it can be merged now.

jsteemann commented 2 years ago

2 out of 18 Travis CI sub-jobs failed during git clone. This is likely due to Github's outage yesterday.

jsteemann commented 2 years ago

Is there a chance this PR can make it into a future version of snowball?

jsteemann commented 2 years ago

Any chance this PR can make it into a future version of snowball?

ojwb commented 1 year ago

I'll merge the patch, but I'd really strongly recommend using LSAN_OPTIONS=leak_check_at_exit=0 when running snowball to avoid this sort of problem (as I suggested in the other ticket).

Doing that would address the issue for you once and for all; otherwise next time the code changes such that something is allocated and not released on exit you'll have to spend time submitting another patch and I'll have to spend time reviewing and applying it.

ojwb commented 1 year ago

This patch introduce a bogus -1 blocks unfreed message at the end of every run, fixed in 4af181be519a0dbdf5d3657ac86ce03db5eb9011.