From 9acf130adb7deffb49e24a52b4e7c8130ba445ae Mon Sep 17 00:00:00 2001 From: radimch Date: Fri, 9 Aug 2013 12:18:16 +0200 Subject: [PATCH] resource leak: FileInputStream was never closed --- .../main/java/io/netty/example/filetransfer/FileServer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/example/src/main/java/io/netty/example/filetransfer/FileServer.java b/example/src/main/java/io/netty/example/filetransfer/FileServer.java index 550087c227..b589c2e4df 100644 --- a/example/src/main/java/io/netty/example/filetransfer/FileServer.java +++ b/example/src/main/java/io/netty/example/filetransfer/FileServer.java @@ -101,9 +101,11 @@ public class FileServer { return; } ctx.write(file + " " + file.length() + '\n'); - FileRegion region = new DefaultFileRegion(new FileInputStream(file).getChannel(), 0, file.length()); + FileInputStream fis = new FileInputStream(file); + FileRegion region = new DefaultFileRegion(fis.getChannel(), 0, file.length()); ctx.write(region); ctx.writeAndFlush("\n"); + fis.close(); } else { ctx.writeAndFlush("File not found: " + file + '\n'); }