Skip to content

Commit

Permalink
Fix resource leak in SysfsUsbSerialScanner (#3513)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored Apr 1, 2023
1 parent 74052e7 commit 8aa9e11
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,18 @@ private Set<SerialPortInfo> getSerialPortInfos() throws IOException {
Path devSerialDir = Path.of(DEV_SERIAL_BY_ID_DIRECTORY);
if (exists(devSerialDir) && isDirectory(devSerialDir) && isReadable(devSerialDir)) {
// browse serial/by-id directory :
for (Path devLinkPath : newDirectoryStream(devSerialDir)) {
if (Files.isSymbolicLink(devLinkPath)) {
Path devicePath = getRealDevicePath(devLinkPath);
if (devicePath != null) {
String serialPortName = devicePath.getFileName().toString();
// get the corresponding real sysinfo special dir :
Path sysfsDevicePath = getRealDevicePath(
Paths.get(sysfsTtyDevicesDirectory).resolve(serialPortName));
if (sysfsDevicePath != null && isReadable(devicePath) && isWritable(devicePath)) {
result.add(new SerialPortInfo(devLinkPath, sysfsDevicePath));
try (DirectoryStream<Path> directoryStream = newDirectoryStream(devSerialDir)) {
for (Path devLinkPath : directoryStream) {
if (Files.isSymbolicLink(devLinkPath)) {
Path devicePath = getRealDevicePath(devLinkPath);
if (devicePath != null) {
String serialPortName = devicePath.getFileName().toString();
// get the corresponding real sysinfo special dir :
Path sysfsDevicePath = getRealDevicePath(
Paths.get(sysfsTtyDevicesDirectory).resolve(serialPortName));
if (sysfsDevicePath != null && isReadable(devicePath) && isWritable(devicePath)) {
result.add(new SerialPortInfo(devLinkPath, sysfsDevicePath));
}
}
}
}
Expand Down

0 comments on commit 8aa9e11

Please sign in to comment.