mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-10 06:02:09 +00:00
Dispose XML parser with finally
This commit is contained in:
parent
44037991d2
commit
0001ee2651
@ -562,14 +562,18 @@ class LibrarySymbolTable {
|
||||
}
|
||||
// TODO: should consider checking version instead of last modified
|
||||
XmlPullParser parser = XmlPullParserFactory.create(exportsFile, ERROR_HANDLER, false);
|
||||
XmlElement start = parser.start("LIBRARY");
|
||||
String path = start.getAttribute("PATH");
|
||||
String dateString = start.getAttribute("DATE");
|
||||
parser.dispose();
|
||||
Date date = TIMESTAMP_FORMAT.parse(dateString);
|
||||
long lastModifiedSeconds = (libraryFile.lastModified() / 1000) * 1000; // file time in seconds
|
||||
return date.equals(new Date(lastModifiedSeconds)) &&
|
||||
path.equalsIgnoreCase(libraryFile.getAbsolutePath());
|
||||
try {
|
||||
XmlElement start = parser.start("LIBRARY");
|
||||
String path = start.getAttribute("PATH");
|
||||
String dateString = start.getAttribute("DATE");
|
||||
Date date = TIMESTAMP_FORMAT.parse(dateString);
|
||||
long lastModifiedSeconds = (libraryFile.lastModified() / 1000) * 1000; // file time in seconds
|
||||
return date.equals(new Date(lastModifiedSeconds)) &&
|
||||
path.equalsIgnoreCase(libraryFile.getAbsolutePath());
|
||||
}
|
||||
finally {
|
||||
parser.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static final ErrorHandler ERROR_HANDLER = new ErrorHandler() {
|
||||
|
@ -78,9 +78,7 @@ public class QueryOpinionService {
|
||||
QueryOpinionServiceHandler.read(parser);
|
||||
}
|
||||
finally {
|
||||
if (parser != null) {
|
||||
parser.dispose();
|
||||
}
|
||||
parser.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,9 +149,9 @@ public class SleighLanguage implements Language {
|
||||
}
|
||||
|
||||
private boolean isSLAWrongVersion(ResourceFile slaFile) {
|
||||
|
||||
XmlPullParser parser = null;
|
||||
try {
|
||||
XmlPullParser parser = XmlPullParserFactory.create(slaFile, new ErrorHandler() {
|
||||
parser = XmlPullParserFactory.create(slaFile, new ErrorHandler() {
|
||||
|
||||
@Override
|
||||
public void warning(SAXParseException exception) throws SAXException {
|
||||
@ -180,6 +180,11 @@ public class SleighLanguage implements Language {
|
||||
catch (SAXException | IOException e) {
|
||||
return true;
|
||||
}
|
||||
finally {
|
||||
if (parser != null) {
|
||||
parser.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSLAStale(ResourceFile slaFile) {
|
||||
@ -536,20 +541,24 @@ public class SleighLanguage implements Language {
|
||||
private void readInitialDescription() throws SAXException, IOException {
|
||||
ResourceFile specFile = description.getSpecFile();
|
||||
XmlPullParser parser = XmlPullParserFactory.create(specFile, SPEC_ERR_HANDLER, false);
|
||||
XmlElement nextElement = parser.peek();
|
||||
while (nextElement != null && !nextElement.getName().equals("segmented_address")) {
|
||||
parser.next(); // skip element
|
||||
nextElement = parser.peek();
|
||||
}
|
||||
if (nextElement != null) {
|
||||
XmlElement element = parser.start(); // segmented_address element
|
||||
segmentedspace = element.getAttribute("space");
|
||||
segmentType = element.getAttribute("type");
|
||||
if (segmentType == null) {
|
||||
segmentType = "";
|
||||
try {
|
||||
XmlElement nextElement = parser.peek();
|
||||
while (nextElement != null && !nextElement.getName().equals("segmented_address")) {
|
||||
parser.next(); // skip element
|
||||
nextElement = parser.peek();
|
||||
}
|
||||
if (nextElement != null) {
|
||||
XmlElement element = parser.start(); // segmented_address element
|
||||
segmentedspace = element.getAttribute("space");
|
||||
segmentType = element.getAttribute("type");
|
||||
if (segmentType == null) {
|
||||
segmentType = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
parser.dispose();
|
||||
finally {
|
||||
parser.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void setDefaultDataSpace(String spaceName) {
|
||||
@ -842,8 +851,12 @@ public class SleighLanguage implements Language {
|
||||
private void readRemainingSpecification() throws SAXException, IOException {
|
||||
ResourceFile specFile = description.getSpecFile();
|
||||
XmlPullParser parser = XmlPullParserFactory.create(specFile, SPEC_ERR_HANDLER, false);
|
||||
read(parser);
|
||||
parser.dispose();
|
||||
try {
|
||||
read(parser);
|
||||
}
|
||||
finally {
|
||||
parser.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void readSpecification(final ResourceFile sleighfile)
|
||||
@ -865,8 +878,12 @@ public class SleighLanguage implements Language {
|
||||
}
|
||||
};
|
||||
XmlPullParser parser = XmlPullParserFactory.create(sleighfile, errHandler, false);
|
||||
restoreXml(parser);
|
||||
parser.dispose();
|
||||
try {
|
||||
restoreXml(parser);
|
||||
}
|
||||
finally {
|
||||
parser.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreXml(XmlPullParser parser) throws UnknownInstructionException {
|
||||
|
@ -177,8 +177,12 @@ public class SleighLanguageProvider implements LanguageProvider {
|
||||
}
|
||||
};
|
||||
XmlPullParser parser = XmlPullParserFactory.create(specFile, errHandler, false);
|
||||
read(parser, specFile.getParentFile(), specFile.getName());
|
||||
parser.dispose();
|
||||
try {
|
||||
read(parser, specFile.getParentFile(), specFile.getName());
|
||||
}
|
||||
finally {
|
||||
parser.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void read(XmlPullParser parser, ResourceFile parentDirectory, String ldefs) {
|
||||
|
Loading…
Reference in New Issue
Block a user