Open apismensky opened 10 months ago
The reason for the bug is that every call allocScratch
calls scratch.registerDeallocator();
and this guy calls hs_scratch_t p = new hs_scratch_t(this);
which effectively calls hs_scratch_t method twice for the same scanner object. We may fix that by checking if the deallocator instance is created, for example:
private static class NativeScratch extends hs_scratch_t {
void registerDeallocator() {
if (deallocator() != null) {
hs_scratch_t p = new hs_scratch_t(this);
deallocator(() -> hs_free_scratch(p));
}
}
@gliwka - lmk I can create a PR for that, but wanted to know what you think?
@apismensky Thanks for the analysis. PR is welcome :-)
Thanks for providing the fix @apismensky and for merging it @gliwka! Would it be possible to make a new release to easily make the fix available (and close this issue)?
This article https://intel.github.io/hyperscan/dev-reference/performance.html#allocate-one-scratch-space-per-scanning-context says that one scratch space can be used with multiple databases. But this snipped of code produces an exception:
Most probably the bug is in the java wrapper, cause the following C++ code works fine (no error):