[ 
https://issues.apache.org/jira/browse/HADOOP-7090?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12978188#action_12978188
 ] 

Owen O'Malley commented on HADOOP-7090:
---------------------------------------

See my comment at 
https://issues.apache.org/jira/browse/MAPREDUCE-2243?focusedCommentId=12977849&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_12977849

The nominal close must be done in the try block. Only the exceptional close 
must be done in a catch block.

> Possible resource leaks in hadoop core code
> -------------------------------------------
>
>                 Key: HADOOP-7090
>                 URL: https://issues.apache.org/jira/browse/HADOOP-7090
>             Project: Hadoop Common
>          Issue Type: Bug
>    Affects Versions: 0.21.0
>            Reporter: Gokul
>
> It is always a good practice to close the IO streams in a finally block.. 
> For example, look at the following piece of code in the Writer class of 
> BloomMapFile 
> {code:title=BloomMapFile .java|borderStyle=solid}
>     public synchronized void close() throws IOException {
>       super.close();
>       DataOutputStream out = fs.create(new Path(dir, BLOOM_FILE_NAME), true);
>       bloomFilter.write(out);
>       out.flush();
>       out.close();
>     }
> {code} 
> If an exception occurs during fs.create or on any other line,  out.close() 
> will not be executed..
> The following can reduce the scope of resorce leaks..
> {code:title=BloomMapFile .java|borderStyle=solid}
>     public synchronized void close() throws IOException {
>       super.close();
>       DataOutputStream out = null;
>       try{
>           out = fs.create(new Path(dir, BLOOM_FILE_NAME), true);
>           bloomFilter.write(out);
>           out.flush();
>       }finally{
>        IOUtils.closeStream(out);
>     }
> {code} 

-- 
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