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
1 changed files with 13 additions and 5 deletions

View File

@ -651,12 +651,20 @@ private synchronized void copyRecursive( String sourcePath, MountWrapper sourceM
}
}
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 void flush() throws IOException
throw new UnsupportedOperationException();
}
};
return (IMountedFileNormal) openFile( file );
return (IMountedFileNormal) openFile( file, reader );
}
return null;
}
@ -773,7 +781,7 @@ public void flush() throws IOException
writer.flush();
}
};
return (IMountedFileNormal) openFile( file );
return (IMountedFileNormal) openFile( file, writer );
}
return null;
}
@ -811,7 +819,7 @@ public void flush() throws IOException
throw new UnsupportedOperationException();
}
};
return (IMountedFileBinary) openFile( file );
return (IMountedFileBinary) openFile( file, stream );
}
return null;
}
@ -849,7 +857,7 @@ public void flush() throws IOException
stream.flush();
}
};
return (IMountedFileBinary) openFile( file );
return (IMountedFileBinary) openFile( file, stream );
}
return null;
}