[ 
https://issues.apache.org/activemq/browse/SM-1012?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_39787
 ] 

Artur Karazniewicz commented on SM-1012:
----------------------------------------

I realized that this bug concerns not only LW FilePoller, but JBI 
(org.apache.servicemix.file.FilePollerEndpoint) also.

> Possible resource leak in FilePoller
> ------------------------------------
>
>                 Key: SM-1012
>                 URL: https://issues.apache.org/activemq/browse/SM-1012
>             Project: ServiceMix
>          Issue Type: Bug
>          Components: servicemix-file
>    Affects Versions: 3.1.1
>         Environment: Windows XP, JDK 5.0
>            Reporter: Artur Karazniewicz
>            Priority: Minor
>
> In the org.apache.servicemix.components.file.FilePoller#processFile(File) it 
> is possible that allocated file would leak. Now, it goes like:
>   protected void processFile(File aFile) throws Exception {
>         String name = aFile.getCanonicalPath();
>         InputStream in = new BufferedInputStream(new FileInputStream(aFile));
>         InOnly exchange = getExchangeFactory().createInOnlyExchange();
>         NormalizedMessage message = exchange.createMessage();
>         exchange.setInMessage(message);
>         marshaler.readMessage(exchange, message, in, name);
>         getDeliveryChannel().sendSync(exchange);
>         in.close();
>     }
> But, we should properly clean-up in the case of exception thrown before 
> in.close(). Thus, should be:
>   protected void processFile(File aFile) throws Exception {
>               InputStream in = null;
>               try {
>                       String name = aFile.getCanonicalPath();
>                       in = new BufferedInputStream(new 
> FileInputStream(aFile));
>                       InOnly exchange = 
> getExchangeFactory().createInOnlyExchange();
>                       NormalizedMessage message = exchange.createMessage();
>                       exchange.setInMessage(message);
>                       marshaler.readMessage(exchange, message, in, name);
>                       getDeliveryChannel().sendSync(exchange);
>               } 
>               finally {
>                       if (in != null) {
>                               in.close();
>                       }
>               }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to