When running a code analysis tool including several sub tools (mainly Coverty [1]), some issues were detected by it.
You can refer attached issues_report.txt for detail.
Some issues in the issues_report.txt might be false positive.
(Those might be wrongly detected.)
To be clear, those 9 issues about mainly leaked resource in the attached report file are marked as "important" by the analysis tool for ruby 2.5.1 + some patch files.
Total 9
1 COPY_PASTE_ERROR
7 RESOURCE_LEAK
1 USE_AFTER_FREE
However as a "not important" issues, around 1000 issues were detected by the tool for the ruby 2.5.1.
I am considering how to deal with this or report those.
I might open an another ticket for that.
In the case of pty.c, the "leaked handle" was not detected for the return value of rb_cloexec_open. even when close function can be executed for for the return value "slave" (= file descriptor) == 0, 1 or 2.
In process.c, when the return value n < 0, is it no problem?
Upon successful completion, these functions shall open the file and return a non-negative integer representing the file descriptor. Otherwise, these functions shall return -1 and set errno to indicate the error. If -1 is returned, no files shall be created or modified.
pty.c should be more defensive too, thank you for pointing out.