Zaboj Campula
Zaboj Campula

Reputation: 3360

JVM memory leak in Process.exec()

My Java application do a lot of execution of external processes. The memory consumption of the application steadily grows. A minimal example reproducing the error:

import java.io.IOException;
public class JSpawnTest {
    public static void main(String[] args) {
    while(true) {
        try {
            Process p = Runtime.getRuntime().exec("ls");
            p.waitFor();
            p.getOutputStream().close();
            p.getInputStream().close();
            p.getErrorStream().close();
        } catch (InterruptedException | IOException e) {
            e.printStackTrace();
        }
    }
}

Each call Process.exec().waitFor() allocates 64 bytes that are never freed. These allocated memory contains the pattern:

...
00 00 00 00 45 00 00 00  2f 75 73 72 2f 6c 69 62  |....E.../usr/lib|
2f 6a 76 6d 2f 6a 61 76  61 2d 37 2d 6f 70 65 6e  |/jvm/java-7-open|
6a 64 6b 2f 6a 72 65 2f  6c 69 62 2f 61 72 6d 2f  |jdk/jre/lib/arm/|
6a 73 70 61 77 6e 68 65  6c 70 65 72 00 8b 52 39  |jspawnhelper..R9|
00 00 00 00 45 00 00 00  2f 75 73 72 2f 6c 69 62  |....E.../usr/lib|
2f 6a 76 6d 2f 6a 61 76  61 2d 37 2d 6f 70 65 6e  |/jvm/java-7-open|
...

I observe the error only at an ARM linux machine with JVM:

java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (75b13-2.5.4)
OpenJDK Zero VM (build 24.80-b07, mixed mode)

I tried the same at x86 linux and the problem does not occur.

I have not found a related bug in JVM bug database but I do not want to blame JVM because all my previous attempts to blame JVM ended with my shame.

Is there anything bad with the code above that could cause a leak or is it an unknown/known JVM bug?

Upvotes: 0

Views: 1135

Answers (1)

the8472
the8472

Reputation: 43107

A simple search for "waitFor leak" on the openjdk bug tracker reveals that this is probably JDK-8054841 which is already fixed.

Update to a current version.

Upvotes: 4

Related Questions