Sfoglia il codice sorgente

Merge -r 1170285:1170286 from branch-0.20-security to branch-0.20-security-205 to fix MAPREDUCE-2549.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-205@1170287 13f79535-47bb-0310-9956-ffa450edef68
Arun Murthy 13 anni fa
parent
commit
41d02ace5c

+ 3 - 0
CHANGES.txt

@@ -136,6 +136,9 @@ Release 0.20.205.0 - 2011.09.12
 
 
     HADOOP-7626. Bugfix for a config generator (Eric Yang via ddas)
     HADOOP-7626. Bugfix for a config generator (Eric Yang via ddas)
 
 
+    MAPREDUCE-2549. Fix resource leaks in Eclipse plugin. (Devaraj K via
+    acmurthy) 
+
   IMPROVEMENTS
   IMPROVEMENTS
 
 
     MAPREDUCE-2187. Reporter sends progress during sort/merge. (Anupam Seth via
     MAPREDUCE-2187. Reporter sends progress during sort/merge. (Anupam Seth via

+ 8 - 2
src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/server/HadoopServer.java

@@ -36,6 +36,7 @@ import javax.xml.parsers.ParserConfigurationException;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.eclipse.Activator;
 import org.apache.hadoop.eclipse.Activator;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.mapred.JobClient;
 import org.apache.hadoop.mapred.JobClient;
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.JobID;
 import org.apache.hadoop.mapred.JobID;
@@ -420,8 +421,13 @@ public class HadoopServer {
    */
    */
   public void storeSettingsToFile(File file) throws IOException {
   public void storeSettingsToFile(File file) throws IOException {
     FileOutputStream fos = new FileOutputStream(file);
     FileOutputStream fos = new FileOutputStream(file);
-    this.conf.writeXml(fos);
-    fos.close();
+    try {
+      this.conf.writeXml(fos);
+      fos.close();
+      fos = null;
+    } finally {
+      IOUtils.closeStream(fos);
+    }
   }
   }
 
 
   /* @inheritDoc */
   /* @inheritDoc */

+ 8 - 2
src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/servers/RunOnHadoopWizard.java

@@ -28,6 +28,7 @@ import org.apache.hadoop.eclipse.Activator;
 import org.apache.hadoop.eclipse.ErrorMessageDialog;
 import org.apache.hadoop.eclipse.ErrorMessageDialog;
 import org.apache.hadoop.eclipse.server.HadoopServer;
 import org.apache.hadoop.eclipse.server.HadoopServer;
 import org.apache.hadoop.eclipse.server.JarModule;
 import org.apache.hadoop.eclipse.server.JarModule;
+import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.JobConf;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.CoreException;
@@ -163,8 +164,13 @@ public class RunOnHadoopWizard extends Wizard {
       // confDir);
       // confDir);
       File confFile = new File(confDir, "core-site.xml");
       File confFile = new File(confDir, "core-site.xml");
       FileOutputStream fos = new FileOutputStream(confFile);
       FileOutputStream fos = new FileOutputStream(confFile);
-      conf.writeXml(fos);
-      fos.close();
+      try {
+        conf.writeXml(fos);
+        fos.close();
+        fos = null;
+      } finally {
+        IOUtils.closeStream(fos);
+      }
 
 
     } catch (IOException ioe) {
     } catch (IOException ioe) {
       ioe.printStackTrace();
       ioe.printStackTrace();

+ 17 - 9
src/contrib/streaming/src/java/org/apache/hadoop/streaming/Environment.java

@@ -22,6 +22,8 @@ import java.io.*;
 import java.net.InetAddress;
 import java.net.InetAddress;
 import java.util.*;
 import java.util.*;
 
 
+import org.apache.hadoop.io.IOUtils;
+
 /**
 /**
  * This is a class used to get the current environment
  * This is a class used to get the current environment
  * on the host machines running the map/reduce. This class
  * on the host machines running the map/reduce. This class
@@ -57,17 +59,23 @@ public class Environment extends Properties {
 
 
     Process pid = Runtime.getRuntime().exec(command);
     Process pid = Runtime.getRuntime().exec(command);
     BufferedReader in = new BufferedReader(new InputStreamReader(pid.getInputStream()));
     BufferedReader in = new BufferedReader(new InputStreamReader(pid.getInputStream()));
-    while (true) {
-      String line = in.readLine();
-      if (line == null) break;
-      int p = line.indexOf("=");
-      if (p != -1) {
-        String name = line.substring(0, p);
-        String value = line.substring(p + 1);
-        setProperty(name, value);
+    try {
+      while (true) {
+        String line = in.readLine();
+        if (line == null)
+          break;
+        int p = line.indexOf("=");
+        if (p != -1) {
+          String name = line.substring(0, p);
+          String value = line.substring(p + 1);
+          setProperty(name, value);
+        }
       }
       }
+      in.close();
+      in = null;
+    } finally {
+      IOUtils.closeStream(in);
     }
     }
-    in.close();
     try {
     try {
       pid.waitFor();
       pid.waitFor();
     } catch (InterruptedException e) {
     } catch (InterruptedException e) {