You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Torsten Curdt (JIRA)" <ji...@apache.org> on 2010/04/13 22:41:51 UTC

[jira] Closed: (SANDBOX-314) ContinuationClassLoader does not close output stream in getClassFromStream(InputStream,String)

     [ https://issues.apache.org/jira/browse/SANDBOX-314?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Torsten Curdt closed SANDBOX-314.
---------------------------------


> 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
>            Assignee: Torsten Curdt
>            Priority: Minor
>         Attachments: ContinuationClassLoader.txt
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> 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.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira