commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Subhajit DasGupta (JIRA)" <j...@apache.org>
Subject [jira] Created: (SANDBOX-314) ContinuationClassLoader does not close output stream in getClassFromStream(InputStream,String)
Date Sun, 18 Oct 2009 13:19:31 GMT
ContinuationClassLoader does not close output stream in getClassFromStream(InputStream,String)
----------------------------------------------------------------------------------------------

                 Key: SANDBOX-314
                 URL: https://issues.apache.org/jira/browse/SANDBOX-314
             Project: Commons Sandbox
          Issue Type: Bug
          Components: Javaflow
         Environment: This is a problem with the way the getClassFromStream method is coded.
The problem is independent of the environment.
            Reporter: Subhajit DasGupta
            Priority: Minor


The getClassFromStream(InputStream,String) method creates a ByteArrayOutputStream but fails
to close it after it finishes using it. This could lead to memory leaks in long running programs
using the "getClassFromStream" method. I am submitting a patch below. This code opens and
uses the ByteArrayIOutputStream object "baos" inside a "try", and closes baos in a "finally"
block.

Index: ContinuationClassLoader.java
===================================================================
--- ContinuationClassLoader.java	(revision 826428)
+++ ContinuationClassLoader.java	(working copy)
@@ -350,7 +350,9 @@
      */
     private Class getClassFromStream(InputStream stream, String classname)
                 throws IOException, SecurityException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ByteArrayOutputStream baos = null;
+        try{
+        baos = new ByteArrayOutputStream();
         int bytesRead;
         byte[] buffer = new byte[BUFFER_SIZE];
 
@@ -360,6 +362,11 @@
 
         byte[] classData = baos.toByteArray();
         return defineClassFromData(classData, classname);
+        }finally{
+            if ( baos != null ){
+                baos.close();
+            }
+        }
     }
 
     /**




-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message