coverity#1371372 Resource leak on an exceptional path
and coverity#1371366 Resource leak on an exceptional path coverity#1371376 Resource leak on an exceptional path Change-Id: Ic0fd05f02b1d78a47d4ee924dee8f10811586d0d
This commit is contained in:
@@ -31,7 +31,7 @@ public class ClassLoaderFactory {
|
||||
|
||||
private ClassLoaderFactory() {}
|
||||
|
||||
public static ClassLoader getURLClassLoader(ScriptMetaData scriptData) {
|
||||
public static URLClassLoader getURLClassLoader(ScriptMetaData scriptData) {
|
||||
ClassLoader parent = scriptData.getClass().getClassLoader();
|
||||
URL[] classPath = scriptData.getClassPath();
|
||||
LogUtils.DEBUG("Classpath has length " + classPath.length);
|
||||
@@ -43,8 +43,8 @@ public class ClassLoaderFactory {
|
||||
return getURLClassLoader(parent, classPath);
|
||||
}
|
||||
|
||||
private static ClassLoader getURLClassLoader(ClassLoader parent,
|
||||
private static URLClassLoader getURLClassLoader(ClassLoader parent,
|
||||
URL[] classpath) {
|
||||
return new URLClassLoader(classpath, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -180,15 +181,14 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener {
|
||||
*/
|
||||
public void edit(final XScriptContext context, ScriptMetaData entry) {
|
||||
if (entry != null) {
|
||||
URLClassLoader cl = null;
|
||||
try {
|
||||
ClassLoader cl = null;
|
||||
|
||||
try {
|
||||
cl = ClassLoaderFactory.getURLClassLoader(entry);
|
||||
} catch (Exception ignore) { // TODO re-examine error handling
|
||||
}
|
||||
|
||||
final ClassLoader theCl = cl;
|
||||
final URLClassLoader theCl = cl;
|
||||
final URL url = entry.getSourceURL();
|
||||
SwingInvocation.invoke(
|
||||
new Runnable() {
|
||||
@@ -210,6 +210,12 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener {
|
||||
});
|
||||
} catch (IOException ioe) {
|
||||
showErrorMessage("Error loading file: " + ioe.getMessage());
|
||||
if (cl != null) {
|
||||
try {
|
||||
cl.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,9 @@ import com.sun.star.uno.Any;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
@@ -182,13 +184,19 @@ class ScriptImpl implements XScript {
|
||||
aOutParamIndex[0] = new short[0];
|
||||
aOutParam[0] = new Object[0];
|
||||
|
||||
ClassLoader cl = null;
|
||||
URLClassLoader cl = null;
|
||||
URL sourceUrl = null;
|
||||
|
||||
try {
|
||||
cl = ClassLoaderFactory.getURLClassLoader(metaData);
|
||||
sourceUrl = metaData.getSourceURL();
|
||||
} catch (java.net.MalformedURLException mfu) {
|
||||
if (cl != null) {
|
||||
try {
|
||||
cl.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
// Framework error
|
||||
throw new ScriptFrameworkErrorException(
|
||||
mfu.getMessage(), null,
|
||||
|
@@ -44,7 +44,9 @@ import com.sun.star.script.provider.XScript;
|
||||
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ImporterTopLevel;
|
||||
@@ -181,12 +183,18 @@ class ScriptImpl implements XScript {
|
||||
aOutParamIndex[0] = new short[0];
|
||||
aOutParam[0] = new Object[0];
|
||||
|
||||
ClassLoader cl = null;
|
||||
URLClassLoader cl = null;
|
||||
|
||||
try {
|
||||
cl = ClassLoaderFactory.getURLClassLoader(metaData);
|
||||
metaData.getSourceURL();
|
||||
} catch (java.net.MalformedURLException mfu) {
|
||||
if (cl != null) {
|
||||
try {
|
||||
cl.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
throw new ScriptFrameworkErrorException(
|
||||
mfu.getMessage(), null,
|
||||
metaData.getLanguageName(), metaData.getLanguage(),
|
||||
|
Reference in New Issue
Block a user