Fix for a "file handler" leak in native openPort method.

This bug leads to VM crashes (at least on Linux) when the number
of "leaked" handlers goes over 1024 and a select is made on one of
them (for example during readBytes).
This commit is contained in:
Cristian Maglie 2014-01-18 13:12:17 +01:00
parent b61c224cb8
commit a743b53b86
2 changed files with 2 additions and 0 deletions

View File

@ -72,6 +72,7 @@ JNIEXPORT jlong JNICALL Java_jssc_SerialNativeInterface_openPort(JNIEnv *env, jo
fcntl(hComm, F_SETFL, flags);
}
else {
close(hComm);
hComm = jssc_SerialNativeInterface_ERR_INCORRECT_SERIAL_PORT;//-4;
}
delete settings;

View File

@ -57,6 +57,7 @@ JNIEXPORT jlong JNICALL Java_jssc_SerialNativeInterface_openPort(JNIEnv *env, jo
if(hComm != INVALID_HANDLE_VALUE){
DCB *dcb = new DCB();
if(!GetCommState(hComm, dcb)){
CloseHandle(hComm);
hComm = (HANDLE)jssc_SerialNativeInterface_ERR_INCORRECT_SERIAL_PORT;//(-4)Incorrect serial port
}
delete dcb;