DimeBodyPart.send() does not close file handle
----------------------------------------------

                 Key: AXIS-2560
                 URL: http://issues.apache.org/jira/browse/AXIS-2560
             Project: Apache Axis
          Issue Type: Bug
          Components: Basic Architecture
    Affects Versions: 1.3
         Environment: ubuntu 6.06:
 Linux xxxxxx  2.6.15-26-server #1 SMP Thu Aug 3 04:09:15 UTC 2006 i686 
GNU/Linux
Axis 1.3 being used in a custom client software.


            Reporter: Nathan P Sharp


There are two versions of DimeBodyPart.send(), one of them explicitly closes 
the InputStream received from the DataHandler passed in because of Issue 
AXIS-664, the other does not.  Unfortunately the code at 
write(java.io.OutputStream os, byte position, long maxchunk) appears to always 
redirect the call to the version of send() that does not close the file handle. 
 This is constituting a filehandle leak on our system.

Theoretically, changing the code to do the same type of try/finally clause as 
the other send() function would fix the problem:

    /**
     * Special case for dynamically generated content. 
     * maxchunk is currently ignored since the default is 2GB.
     * The chunk size is retrieved from the DynamicContentDataHandler
     * 
     * @param os
     * @param position
     * @param dh
     * @param maxchunk
     * @throws java.io.IOException
     */
    void send(java.io.OutputStream os, byte position, DynamicContentDataHandler 
dh,
            final long maxchunk)
            throws java.io.IOException {
        
                BufferedInputStream in = null;
                try {
                        in = new BufferedInputStream(dh.getInputStream());
                
                        final int myChunkSize = dh.getChunkSize();
                        
                        byte[] buffer1 = new byte[myChunkSize]; 
                        byte[] buffer2 = new byte[myChunkSize]; 
                        
                        int bytesRead1 = 0 , bytesRead2 = 0;
        
                        bytesRead1 = in.read(buffer1);
                        
                        if(bytesRead1 < 0) {
                        sendHeader(os, position, 0, ONLY_CHUNK);
                        os.write(pad, 0, dimePadding(0));
                        return;
                        }
                        byte chunkbyte = CHUNK;
                        do {
                                bytesRead2 = in.read(buffer2);
                                
                                if(bytesRead2 < 0) {
                                        //last record...do not set the chunk 
bit.
                                        //buffer1 contains the last chunked 
record!!
                                
                                //Need to distinguish if this is the first 
                                //chunk to ensure the TYPE and ID are sent
                                if ( chunkbyte == CHUNK ){
                                        chunkbyte = ONLY_CHUNK;
                                } else {
                                        chunkbyte = LAST_CHUNK;
                                }
                                        sendChunk(os, position, buffer1, 0, 
bytesRead1, chunkbyte);
                                        break;
                                }
                                
                                sendChunk(os, position, buffer1, 0, bytesRead1, 
chunkbyte);
                                //set chunk byte to next chunk flag to avoid
                                //sending TYPE and ID on subsequent chunks
                                chunkbyte = CHUNK_NEXT;
                                //now that we have written out buffer1, copy 
buffer2 into to buffer1
                                
System.arraycopy(buffer2,0,buffer1,0,myChunkSize);
                                bytesRead1 = bytesRead2;
                                
                        }while(bytesRead2 > 0);
                }
                finally {
                        if (in != null) {
                                try {
                                        in.close();
                                }
                                catch (IOException e) {
                                        // ignore
                                }
                        }
                }
    }


/* I have not tried this code, I just did it here for illustration */


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to