Browse Source

filterchains leak classloaders, PR 45439

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@810080 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
0d63880ccc
2 changed files with 29 additions and 1 deletions
  1. +6
    -0
      WHATSNEW
  2. +23
    -1
      src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java

+ 6
- 0
WHATSNEW View File

@@ -474,6 +474,12 @@ Fixed bugs:
it was scanning the same filesets more than once.
Bugzilla Report 43574.

* when using custom filterreaders with the <filterreader classname="">
syntax Ant could leak memory.
The problem didn't occur when using <typedef> or <componentdef> to
define the filterreader which is the recommended approach.
Bugzilla Report 45439.

Other changes:
--------------



+ 23
- 1
src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java View File

@@ -22,6 +22,8 @@ import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
@@ -120,6 +122,8 @@ public final class ChainReaderHelper {
Reader instream = primaryReader;
final int filterReadersCount = filterChains.size();
final Vector finalFilters = new Vector();
final ArrayList/*<AntClassLoader>*/ classLoadersToCleanUp =
new ArrayList/*<AntClassLoader>*/();

for (int i = 0; i < filterReadersCount; i++) {
final FilterChain filterchain =
@@ -152,6 +156,7 @@ public final class ChainReaderHelper {
AntClassLoader al
= pro.createClassLoader(classpath);
clazz = Class.forName(className, true, al);
classLoadersToCleanUp.add(al);
}
if (clazz != null) {
if (!FilterReader.class.isAssignableFrom(clazz)) {
@@ -204,7 +209,24 @@ public final class ChainReaderHelper {
}
}
}
return instream;
final Reader finalReader = instream;
return classLoadersToCleanUp.size() == 0 ? finalReader
: new FilterReader(finalReader) {
public void close() throws IOException {
FileUtils.close(in);
for (Iterator it = classLoadersToCleanUp.iterator();
it.hasNext(); ) {
((AntClassLoader) it.next()).cleanup();
}
}
protected void finalize() throws Throwable {
try {
close();
} finally {
super.finalize();
}
}
};
}

/**


Loading…
Cancel
Save