Fix double free on Crystal::Loader#close_all
#11662
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Crystal::Loader#finalize
calls#close_all
, but the FFI and loader specs call the latter manually, which means that upon a GC cycle all the dynamic library handles are closed once again. This PR prevents this by clearing the list of handles once they are closed.Resolves #11561. I have also confirmed that #11343 with this patch will turn the LLVM 13 CI green. I managed to reproduce this locally with just:
However it seems to happen even on earlier LLVM versions; I tried 9 and 11, and both of them produced the same error. I believe calling
dlclose
more thandlopen
on the same handle is undefined behaviour and it is sheer coincidence the other CI jobs didn't break. The following will show that a double free has indeed occurred:The same spec binary above will print
shared object not open
a few times. The count varies between runs of the binary for some reason.