author | sherman |
Tue, 22 Jun 2010 14:04:36 -0400 | |
changeset 5962 | 0913689fd3a0 |
parent 5506 | 202f599c92aa |
child 27785 | 29d4cb4a8f5e |
permissions | -rw-r--r-- |
1769
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
1769
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
4 |
* |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
8 |
* |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
13 |
* accompanied this code). |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
14 |
* |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
1769
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
22 |
*/ |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
23 |
|
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
24 |
/* |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
25 |
* @test |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
26 |
* @bug 6791458 |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
27 |
* @summary Reading from closed input files leaks native memory |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
28 |
*/ |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
29 |
|
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
30 |
import java.io.*; |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
31 |
|
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
32 |
public class MemoryLeak { |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
33 |
public static void main(String[] args) throws Throwable { |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
34 |
byte[] bytes = new byte[1 << 20]; |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
35 |
String dir = System.getProperty("test.src", "."); |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
36 |
File testFile = new File(dir, "input.txt"); |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
37 |
FileInputStream s = new FileInputStream(testFile); |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
38 |
s.close(); |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
39 |
for (int i = 0; i < 10000; i++) { |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
40 |
try { |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
41 |
s.read(bytes); |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
42 |
throw new Error("expected IOException"); |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
43 |
} catch (IOException _) { |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
44 |
/* OK */ |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
45 |
} catch (OutOfMemoryError oome) { |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
46 |
System.out.printf("Got OutOfMemoryError, i=%d%n", i); |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
47 |
throw oome; |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
48 |
} |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
49 |
} |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
50 |
} |
27a33d1b16ec
6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k
martin
parents:
diff
changeset
|
51 |
} |