Browse Source

HADOOP-3592. Fix a couple of possible file leaks in FileUtil (Bill de hOra via rangadi)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@697274 13f79535-47bb-0310-9956-ffa450edef68
Raghu Angadi 16 years ago
parent
commit
43aee04d5d
2 changed files with 25 additions and 5 deletions
  1. 3 0
      CHANGES.txt
  2. 22 5
      src/core/org/apache/hadoop/fs/FileUtil.java

+ 3 - 0
CHANGES.txt

@@ -687,6 +687,9 @@ Trunk (unreleased changes)
     HADOOP-4077. Setting access and modification time for a file
     HADOOP-4077. Setting access and modification time for a file
     requires write permissions on the file. (dhruba)
     requires write permissions on the file. (dhruba)
 
 
+    HADOOP-3592. Fix a couple of possible file leaks in FileUtil
+    (Bill de hOra via rangadi)
+
 Release 0.18.1 - 2008-09-17
 Release 0.18.1 - 2008-09-17
 
 
   IMPROVEMENTS
   IMPROVEMENTS

+ 22 - 5
src/core/org/apache/hadoop/fs/FileUtil.java

@@ -201,9 +201,17 @@ public class FileUtil {
              deleteSource, overwrite, conf);
              deleteSource, overwrite, conf);
       }
       }
     } else if (srcFS.isFile(src)) {
     } else if (srcFS.isFile(src)) {
-      InputStream in = srcFS.open(src);
-      OutputStream out = dstFS.create(dst, overwrite);
-      IOUtils.copyBytes(in, out, conf, true);
+      InputStream in=null;
+      OutputStream out = null;
+      try {
+        in = srcFS.open(src);
+        out = dstFS.create(dst, overwrite);
+        IOUtils.copyBytes(in, out, conf, true);
+      } catch (IOException e) {
+        IOUtils.closeStream(out);
+        IOUtils.closeStream(in);
+        throw e;
+      }
     } else {
     } else {
       throw new IOException(src.toString() + ": No such file or directory");
       throw new IOException(src.toString() + ": No such file or directory");
     }
     }
@@ -271,8 +279,17 @@ public class FileUtil {
              deleteSource, conf);
              deleteSource, conf);
       }
       }
     } else if (src.isFile()) {
     } else if (src.isFile()) {
-      InputStream in = new FileInputStream(src);
-      IOUtils.copyBytes(in, dstFS.create(dst), conf);
+      InputStream in = null;
+      OutputStream out =null;
+      try {
+        in = new FileInputStream(src);
+        out = dstFS.create(dst);
+        IOUtils.copyBytes(in, out, conf);
+      } catch (IOException e) {
+        IOUtils.closeStream( out );
+        IOUtils.closeStream( in );
+        throw e;
+      }
     } else {
     } else {
       throw new IOException(src.toString() + 
       throw new IOException(src.toString() + 
                             ": No such file or directory");
                             ": No such file or directory");