Fix for a "file handler" leak in native openPort method. #36
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.
First of all, thanks for the great library!
During my tests on the Arduino IDE I've found some sporadic crashes of the JVM.
Looking at the JVM crash logs, the crash happens while JSSC is reading from the serial port with readBytes method.
After some debugging I've discovered that the issue was caused by a resource leak in native openPorts method.
Test case:
and the following is an extract of "lsof" of the resulting process:
As you can see the file handlers are allocated and never released.
This bug leads to VM crashes, at least on Linux, when the number of "leaked" file handlers goes over 1024 and a select is made on one of them (in our case during readBytes).
This pull request fix the problem.
I've successfully compiled and tested on Linux.
Not compiled nor tested on Windows and Mac.