Skip to content

Commit 00eebb1

Browse files
SerialImp.c:RXTXPort(open) - on failure release file descriptor and lock
1 parent b1da316 commit 00eebb1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/c/src/SerialImp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,10 @@ JNIEXPORT jint JNICALL RXTXPort(open)(
738738
}
739739
#endif /* OPEN_EXCL */
740740

741-
if( configure_port( fd ) ) goto fail;
741+
if( configure_port( fd ) ) {
742+
close(fd);
743+
goto fail;
744+
}
742745
(*env)->ReleaseStringUTFChars( env, jstr, filename );
743746
snprintf( message, sizeof(message), "open: fd returned is %i\n", fd );
744747
report( message );
@@ -747,6 +750,7 @@ JNIEXPORT jint JNICALL RXTXPort(open)(
747750
return (jint)fd;
748751

749752
fail:
753+
UNLOCK(filename, pid);
750754
(*env)->ReleaseStringUTFChars( env, jstr, filename );
751755
LEAVE( "RXTXPort:open" );
752756
throw_java_exception( env, PORT_IN_USE_EXCEPTION, "open",

0 commit comments

Comments
 (0)