Author: nextgens
Date: 2007-11-29 12:43:24 +0000 (Thu, 29 Nov 2007)
New Revision: 16075

Modified:
   trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
Log:
FProxyToadlet: don't leak an InputStream

Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java   2007-11-29 
12:41:43 UTC (rev 16074)
+++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java   2007-11-29 
12:43:24 UTC (rev 16075)
@@ -223,13 +223,16 @@
         * REDFLAG Expect future security issues! 
         * @throws IOException */
        private static boolean horribleEvilHack(Bucket data) throws IOException 
{
-               int sz = (int) Math.min(data.size(), 512);
-               if(sz == 0) return false;
-               InputStream is = data.getInputStream();
-               byte[] buf = new byte[sz];
-               // FIXME Fortunately firefox doesn't detect RSS in UTF16 etc 
... yet
-               is.read(buf);
-               /**
+               InputStream is = null;
+               try {
+                       int sz = (int) Math.min(data.size(), 512);
+                       if(sz == 0)
+                               return false;
+                       is = data.getInputStream();
+                       byte[] buf = new byte[sz];
+                       // FIXME Fortunately firefox doesn't detect RSS in 
UTF16 etc ... yet
+                       is.read(buf);
+                       /**
                 * Look for any of the following strings:
                 * <rss
                 * &lt;feed
@@ -238,10 +241,16 @@
                 * If they start at the beginning of the file, or are preceded 
by one or more &lt;! or &lt;? tags,
                 * then firefox will read it as RSS. In which case we must 
force it to be downloaded to disk. 
                 */
-               if(checkForString(buf, "<rss")) return true;
-               if(checkForString(buf, "<feed")) return true;
-               if(checkForString(buf, "<rdf:RDF")) return true;
-               is.close();
+                       if(checkForString(buf, "<rss"))
+                               return true;
+                       if(checkForString(buf, "<feed"))
+                               return true;
+                       if(checkForString(buf, "<rdf:RDF"))
+                               return true;
+               }
+               finally {
+                       is.close();
+               }
                return false;
        }



Reply via email to