Fixed bug with file descriptors leakage

This commit is contained in:
Igor Chevdar
2019-06-05 19:57:09 +03:00
parent 3e8f3e6f00
commit acf9670306
@@ -107,7 +107,8 @@ data class File constructor(internal val javaPath: Path) {
if (mode == FileChannel.MapMode.READ_ONLY) "r" else "rw")
val fileSize = if (mode == FileChannel.MapMode.READ_ONLY)
file.length() else size.also { assert(size != -1L) }
return file.channel.map(mode, start, fileSize) // Shall we .also { file.close() }?
val channel = file.channel
return channel.map(mode, start, fileSize).also { channel.close() }
}
fun deleteOnExit(): File {