Skip to content

Resource leak: Sources not closed #12016

@rethab

Description

@rethab

There are several places in this repo where Source.fromFile is used without closing the source thereafter. While this is likely not a problem in the productive sources (see output below), this has in the past led to issues with running tests on windows.

Note that this issue was originally reported by @michelou in the dotty repo scala/scala3#8358 and @smarter found that this repo has the same issues.

Occurences

note that I excluded Using here because it is actually used in one place

[rethab:~/dev/scala] 2.13.x ± λ git grep "Source.fromFile" *.scala | grep -v Using
project/GenerateFunctionConverters.scala:    val x = scala.io.Source.fromFile(f)
src/library/scala/concurrent/package.scala: *   val source = scala.io.Source.fromFile("/etc/dictionaries-common/words")
src/partest/scala/tools/partest/nest/FileManager.scala:    compareContents(io.Source.fromFile(original).getLines.toSeq, io.Source.fromFile(revised).getLines.toSeq, original.getName, revised.getName)
test/benchmarks/src/main/scala/scala/collection/immutable/GenerateVectorBenchmark2Charts.scala:    Source.fromFile(file, "UTF8").getLines().drop(1).map { s =>
test/files/jvm/t2104.scala:    g(Source.fromFile(f))
test/files/run/t4671.scala:val s = scala.io.Source.fromFile(o.file)
test/files/run/t4671.scala:val s = scala.io.Source.fromFile(o.file)
test/files/run/t6240-universe-code-gen.scala:  val actual = scala.io.Source.fromFile(actualFile)
test/files/specialized/fft.scala:    val f = io.Source.fromFile(inputFileName)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions