Mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthias Ernst (JIRA)" <server-...@james.apache.org>
Subject [jira] Commented: (JAMES-430) MailImpl#writeContentTo leaks thread
Date Fri, 30 Dec 2005 10:45:03 GMT
    [ http://issues.apache.org/jira/browse/JAMES-430?page=comments#action_12361414 ] 

Matthias Ernst commented on JAMES-430:
--------------------------------------

+        BufferedReader br = null;
+        if (message != null) {
+            try {
+                br = new BufferedReader(new InputStreamReader(message.getInputStream()));
+                while (lines-- > 0) {
+                    if ((line = br.readLine()) == null) {
+                        break;
+                    }
+                    line += "\r\n";
+                    out.write(line.getBytes());
+                }
+            } finally {
+                if (br != null) {
+                    br.close();
+                }
+            }
+        } else {
+            throw new MessagingException("No message set for this MailImpl.");
+        }

I've seen this so often. Why such complicated cleanup? You should always start the "try" _AFTER_
you allocate the resource/acquire the lock/... Then the scope of the variable is right and
your don't need to check whether it actually happened.

+           if (message != null) {
+                BufferedReader br = new BufferedReader(new InputStreamReader(message.getInputStream()));
+                try {
+                  while (lines-- > 0) {
+                      if ((line = br.readLine()) == null) {
+                          break;
+                      }
+                      line += "\r\n";
+                      out.write(line.getBytes());
+                    }
+                } finally {
+                    br.close();
+                }
+          } else {
+            throw new MessagingException("No message set for this MailImpl.");
+          }

Matthias


> MailImpl#writeContentTo leaks thread
> ------------------------------------
>
>          Key: JAMES-430
>          URL: http://issues.apache.org/jira/browse/JAMES-430
>      Project: James
>         Type: Bug
>   Components: James Core
>     Versions: 2.2.0
>     Reporter: Matthias Ernst
>     Assignee: Stefano Bagnara
>      Fix For: 2.3.0

>
> MailImpl#writeContentTo(OutputStream, int) (used by POP3 TOP) does not close the input
stream acquired from its MimeMessage. MimeMessage#getInputStream is a PipedInputStream and
has a thread running on its behalf. Thus, MailImpl leaks a thread per
> message TOPed.
> Fix:
> in = message.getInputStream();
> try {
>   ...
> } finally {
>   in.close
> }

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message