1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-03-04 10:38:12 +00:00

Fix file handle leak

This commit is contained in:
Lignum 2017-05-02 00:44:33 +02:00
parent 2a1e110a65
commit 6ff9db89cc
No known key found for this signature in database
GPG Key ID: E4DE8F54CA0912BA

View File

@ -651,12 +651,20 @@ public class FileSystem
}
}
private synchronized IMountedFile openFile( IMountedFile file ) throws FileSystemException
private synchronized IMountedFile openFile( IMountedFile file, Closeable handle ) throws FileSystemException
{
synchronized( m_openFiles )
{
if( m_openFiles.size() >= ComputerCraft.maximumFilesOpen )
{
if( handle != null )
{
try {
handle.close();
} catch ( IOException ignored ) {
// shrug
}
}
throw new FileSystemException("Too many files already open");
}
@ -721,7 +729,7 @@ public class FileSystem
throw new UnsupportedOperationException();
}
};
return (IMountedFileNormal) openFile( file );
return (IMountedFileNormal) openFile( file, reader );
}
return null;
}
@ -773,7 +781,7 @@ public class FileSystem
writer.flush();
}
};
return (IMountedFileNormal) openFile( file );
return (IMountedFileNormal) openFile( file, writer );
}
return null;
}
@ -811,7 +819,7 @@ public class FileSystem
throw new UnsupportedOperationException();
}
};
return (IMountedFileBinary) openFile( file );
return (IMountedFileBinary) openFile( file, stream );
}
return null;
}
@ -849,7 +857,7 @@ public class FileSystem
stream.flush();
}
};
return (IMountedFileBinary) openFile( file );
return (IMountedFileBinary) openFile( file, stream );
}
return null;
}