[#1880] Fix file handle leaks

... in VirtualFile.content and VirtualFile.contentAsString

The most important fix is in file VirtualFile (first commit b4afb68).
Other commits are minor fixes & code cleanup.