You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by "Guangtai Liang (Updated) (JIRA)" <se...@james.apache.org> on 2012/02/23 16:16:49 UTC

[jira] [Updated] (JAMES-1382) An incomplete fix for the resource leak bugs in NNTPHandler.java

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

Guangtai Liang updated JAMES-1382:
----------------------------------

    Description: 
The fix revision 108172 was aimed to remove resource leak bugs on the BufferedReader object "in" (created in line 192), the Socket object "this.socket", the OutputStream object "outs", and the InternetPrintWriter object "out" in the method "handleConnection"of the file "/james/server/trunk/src/java/org/apache/james/pop3server/POP3Handler.java (now moved to /james/server/branches/v2.3/src/java/org/apache/james/pop3server/POP3Handler.java)" , but it is incomplete.

There are some problems: 
1. when "in" isn't created successfully but the temp InputStreamReader object is created successfully (at line 193), the temp InputStreamReader object will be leaked. 
2. when the statements at lines 189-197 throw some exception, "this.socket" and "in" will be leaked. 

The best way to close such resource objects is putting such close operations for all resource objects in the finaly block of a try-catch-finally structure and then putting all other code in a try block.

The problem still exists in the head revision (the temp BufferedInputStream object created at line 233 and the "in" created at line 233 can be leaked). The buggy code is copied as bellows:

/**
     * @see org.apache.avalon.cornerstone.services.connection.ConnectionHandler#handleConnection

(Socket)
     */
    public void handleConnection( Socket connection )
            throws IOException {

        String remoteHost = "";
        String remoteIP = "";

        try {
            this.socket = connection;
            synchronized (this) {
                handlerThread = Thread.currentThread();
            }
 232           // in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "ASCII"), 

512);
 233           in = new CRLFTerminatedReader(new BufferedInputStream(socket.getInputStream(), 512), 

"ASCII");
 234           remoteIP = socket.getInetAddress().getHostAddress ();
 235           remoteHost = socket.getInetAddress().getHostName ();
        } catch (Exception e) {
            ......
        }

250        if (getLogger().isInfoEnabled()) {
            StringBuffer logBuffer =
                new StringBuffer(128)
                        .append("Connection from ")
                        .append(remoteHost)
                        .append(" (")
                        .append(remoteIP)
                        .append(") ");
258            getLogger().info(logBuffer.toString());
        }

        try {
           ......
        } catch (Exception e) {
	   ......
        } finally {
            resetHandler();
        }
    }


  was:
The fix revision 108172 was aimed to remove resource leak bugs on the BufferedReader object "in" (created in line 192), the Socket object "this.socket", the OutputStream object "outs", and the InternetPrintWriter object "out" in the method "handleConnection"of the file "/james/server/trunk/src/java/org/apache/james/nntpserver/NNTPHandler.java (now moved to /james/server/branches/v2.3/src/java/org/apache/james/nntpserver/NNTPHandler.java)" , but it is incomplete.

There are some problems: 
1. when "in" isn't created successfully but the temp InputStreamReader object is created successfully (at line 193), the temp InputStreamReader object will be leaked. 
2. when the statements at lines 189-197 throw some exception, "this.socket" and "in" will be leaked. 

The best way to close such resource objects is putting such close operations for all resource objects in the finaly block of a try-catch-finally structure and then putting all other code in a try block.

The problem still exists in the head revision (the temp BufferedInputStream object created at line 233 and the "in" created at line 233 can be leaked). The buggy code is copied as bellows:

/**
     * @see org.apache.avalon.cornerstone.services.connection.ConnectionHandler#handleConnection

(Socket)
     */
    public void handleConnection( Socket connection )
            throws IOException {

        String remoteHost = "";
        String remoteIP = "";

        try {
            this.socket = connection;
            synchronized (this) {
                handlerThread = Thread.currentThread();
            }
 232           // in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "ASCII"), 

512);
 233           in = new CRLFTerminatedReader(new BufferedInputStream(socket.getInputStream(), 512), 

"ASCII");
 234           remoteIP = socket.getInetAddress().getHostAddress ();
 235           remoteHost = socket.getInetAddress().getHostName ();
        } catch (Exception e) {
            ......
        }

250        if (getLogger().isInfoEnabled()) {
            StringBuffer logBuffer =
                new StringBuffer(128)
                        .append("Connection from ")
                        .append(remoteHost)
                        .append(" (")
                        .append(remoteIP)
                        .append(") ");
258            getLogger().info(logBuffer.toString());
        }

        try {
           ......
        } catch (Exception e) {
	   ......
        } finally {
            resetHandler();
        }
    }


    
> An incomplete fix for the resource leak bugs in NNTPHandler.java
> ----------------------------------------------------------------
>
>                 Key: JAMES-1382
>                 URL: https://issues.apache.org/jira/browse/JAMES-1382
>             Project: JAMES Server
>          Issue Type: Bug
>          Components: NNTPServer & Repository (removed)
>    Affects Versions: 2.3.0, 2.3.1, 2.3.2
>            Reporter: Guangtai Liang
>            Priority: Critical
>              Labels: incomplete_fix, missing_fixes
>   Original Estimate: 10m
>  Remaining Estimate: 10m
>
> The fix revision 108172 was aimed to remove resource leak bugs on the BufferedReader object "in" (created in line 192), the Socket object "this.socket", the OutputStream object "outs", and the InternetPrintWriter object "out" in the method "handleConnection"of the file "/james/server/trunk/src/java/org/apache/james/pop3server/POP3Handler.java (now moved to /james/server/branches/v2.3/src/java/org/apache/james/pop3server/POP3Handler.java)" , but it is incomplete.
> There are some problems: 
> 1. when "in" isn't created successfully but the temp InputStreamReader object is created successfully (at line 193), the temp InputStreamReader object will be leaked. 
> 2. when the statements at lines 189-197 throw some exception, "this.socket" and "in" will be leaked. 
> The best way to close such resource objects is putting such close operations for all resource objects in the finaly block of a try-catch-finally structure and then putting all other code in a try block.
> The problem still exists in the head revision (the temp BufferedInputStream object created at line 233 and the "in" created at line 233 can be leaked). The buggy code is copied as bellows:
> /**
>      * @see org.apache.avalon.cornerstone.services.connection.ConnectionHandler#handleConnection
> (Socket)
>      */
>     public void handleConnection( Socket connection )
>             throws IOException {
>         String remoteHost = "";
>         String remoteIP = "";
>         try {
>             this.socket = connection;
>             synchronized (this) {
>                 handlerThread = Thread.currentThread();
>             }
>  232           // in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "ASCII"), 
> 512);
>  233           in = new CRLFTerminatedReader(new BufferedInputStream(socket.getInputStream(), 512), 
> "ASCII");
>  234           remoteIP = socket.getInetAddress().getHostAddress ();
>  235           remoteHost = socket.getInetAddress().getHostName ();
>         } catch (Exception e) {
>             ......
>         }
> 250        if (getLogger().isInfoEnabled()) {
>             StringBuffer logBuffer =
>                 new StringBuffer(128)
>                         .append("Connection from ")
>                         .append(remoteHost)
>                         .append(" (")
>                         .append(remoteIP)
>                         .append(") ");
> 258            getLogger().info(logBuffer.toString());
>         }
>         try {
>            ......
>         } catch (Exception e) {
> 	   ......
>         } finally {
>             resetHandler();
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org