commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Torsten Curdt (JIRA)" <j...@apache.org>
Subject [jira] Closed: (SANDBOX-314) ContinuationClassLoader does not close output stream in getClassFromStream(InputStream,String)
Date Tue, 13 Apr 2010 20:41:51 GMT

     [ 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

        

Mime
View raw message