# HG changeset patch # User David Barts # Date 1595190722 25200 # Node ID bed255e4c2dc9cf265527079b666801c047dbb6c # Parent 3feeb953d9aea658afedf2630ac58ab80151ca56 Fix file leak on save. diff -r 3feeb953d9ae -r bed255e4c2dc src/name/blackcap/imageprep/Menus.kt --- a/src/name/blackcap/imageprep/Menus.kt Sat Jul 18 14:23:02 2020 -0700 +++ b/src/name/blackcap/imageprep/Menus.kt Sun Jul 19 13:32:02 2020 -0700 @@ -145,13 +145,15 @@ if (ios == null) throw IOException() /* xxx - end workaround */ - val writer = ImageIO.getImageWritersByFormatName("jpeg").next() - val iwp = writer.getDefaultWriteParam().apply { - setCompressionMode(ImageWriteParam.MODE_EXPLICIT) - setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f) + ios.use { + val writer = ImageIO.getImageWritersByFormatName("jpeg").next() + val iwp = writer.getDefaultWriteParam().apply { + setCompressionMode(ImageWriteParam.MODE_EXPLICIT) + setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f) + } + writer.setOutput(it) + writer.write(null, IIOImage(w.image, null, null), iwp) } - writer.setOutput(ios) - writer.write(null, IIOImage(w.image, null, null), iwp) null } catch (e: IOException) { e