[vlma-devel] commit: Close the file even if an exception occured to avoid file descriptor leaks . (Adrien Grand )

git version control git at videolan.org
Sat Aug 2 16:45:23 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sat Aug  2 16:46:24 2008 +0200| [9333dbc7b14486a7511744dcb411b66ad50c2519] | committer: Adrien Grand 

Close the file even if an exception occured to avoid file descriptor leaks.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=9333dbc7b14486a7511744dcb411b66ad50c2519
---

 .../videolan/vlma/web/servlet/RrdGraphServlet.java |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/vlma-webapp/src/main/java/org/videolan/vlma/web/servlet/RrdGraphServlet.java b/vlma-webapp/src/main/java/org/videolan/vlma/web/servlet/RrdGraphServlet.java
index 78af373..62ee4c1 100644
--- a/vlma-webapp/src/main/java/org/videolan/vlma/web/servlet/RrdGraphServlet.java
+++ b/vlma-webapp/src/main/java/org/videolan/vlma/web/servlet/RrdGraphServlet.java
@@ -69,15 +69,18 @@ public class RrdGraphServlet extends HttpServlet {
         File rrdDir = new File(basePath, "rrd");
         File file = new File(rrdDir, serverName + "-" + what + ".png");
 
-        FileInputStream in = new FileInputStream(file.getAbsolutePath());
-
         response.setContentType("image/png");
         ServletOutputStream out = response.getOutputStream();
         byte[] image = new byte[bufsize];
-        while (in.read(image) != -1) {
-            out.write(image);
+
+        FileInputStream in = new FileInputStream(file.getAbsolutePath());
+        try {
+            while (in.read(image) != -1) {
+                out.write(image);
+            }
+        } finally {
+            in.close();
         }
-        in.close();
         out.close();
     }
 



More information about the vlma-devel mailing list