changeset 45725:083026107a26

8181105: Nashorn file descriptor leak Reviewed-by: jlaskey, hannesw, sundar
author anazarov
date Thu, 22 Jun 2017 10:53:21 -0700
parents 9927a9f16738
children bfa5e2e5a105
files nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java nashorn/test/src/jdk/nashorn/internal/test/framework/AbstractScriptRunnable.java nashorn/test/src/jdk/nashorn/internal/test/framework/ScriptRunnable.java
diffstat 3 files changed, 18 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java	Wed Jul 05 23:44:18 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java	Thu Jun 22 10:53:21 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -339,9 +339,11 @@
         protected void loadMeta() throws IOException {
             if (length == 0 && lastModified == 0) {
                 final URLConnection c = url.openConnection();
-                length = c.getContentLength();
-                lastModified = c.getLastModified();
-                debug("loaded metadata for ", url);
+                try (InputStream in = c.getInputStream()) {
+                    length = c.getContentLength();
+                    lastModified = c.getLastModified();
+                    debug("loaded metadata for ", url);
+                }
             }
         }
     }
--- a/nashorn/test/src/jdk/nashorn/internal/test/framework/AbstractScriptRunnable.java	Wed Jul 05 23:44:18 2017 +0200
+++ b/nashorn/test/src/jdk/nashorn/internal/test/framework/AbstractScriptRunnable.java	Thu Jun 22 10:53:21 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -199,7 +199,7 @@
         try {
             return getEvaluator().run(out, err, args);
         } catch (final IOException e) {
-            throw new UnsupportedOperationException("I/O error in initializing shell - cannot redirect output to file");
+            throw new UnsupportedOperationException("I/O error in initializing shell - cannot redirect output to file", e);
         }
     }
 
--- a/nashorn/test/src/jdk/nashorn/internal/test/framework/ScriptRunnable.java	Wed Jul 05 23:44:18 2017 +0200
+++ b/nashorn/test/src/jdk/nashorn/internal/test/framework/ScriptRunnable.java	Thu Jun 22 10:53:21 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -118,9 +118,10 @@
 
         if (errors != 0 || checkCompilerMsg) {
             if (expectCompileFailure || checkCompilerMsg) {
-                final PrintStream outputDest = new PrintStream(new FileOutputStream(errorFileName));
-                TestHelper.dumpFile(outputDest, new StringReader(new String(err.toByteArray())));
-                outputDest.println("--");
+                try (PrintStream outputDest = new PrintStream(new FileOutputStream(errorFileName))) {
+                    TestHelper.dumpFile(outputDest, new StringReader(new String(err.toByteArray())));
+                    outputDest.println("--");
+                }
             } else {
                 log(new String(err.toByteArray()));
             }
@@ -224,7 +225,6 @@
 
         BufferedReader expected;
         if (expectedFile.exists()) {
-            expected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFileName0)));
             // copy expected file overwriting existing file and preserving last
             // modified time of source
             try {
@@ -235,11 +235,14 @@
             } catch (final IOException ex) {
                 fail("failed to copy expected " + expectedFileName + " to " + copyExpectedFileName + ": " + ex.getMessage());
             }
+            expected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFileName0)));
         } else {
             expected = new BufferedReader(new StringReader(""));
         }
 
-        final BufferedReader actual = new BufferedReader(new InputStreamReader(new FileInputStream(outputFileName0)));
-        compare(actual, expected, compareCompilerMsg);
+        try (BufferedReader actual = new BufferedReader(new InputStreamReader(new FileInputStream(outputFileName0)));
+             BufferedReader expected0 = expected){
+            compare(actual, expected0, compareCompilerMsg);
+        }
     }
 }