Ensure all smali files are closed after the writing is complete

This makes sure that all smali files are closed after writing to them by
surrounding the writer code with a try/finally block that closes the output
stream once the writing has completed or when an exception occurs.
This commit is contained in:
Albert Gorski 2016-10-09 21:24:05 -04:00 committed by Ben Gruver
parent e75f2b230a
commit 43669ecc6e

View File

@ -147,16 +147,14 @@ public class Smali {
private static boolean assembleSmaliFile(File smaliFile, DexBuilder dexBuilder, SmaliOptions options)
throws Exception {
CommonTokenStream tokens;
LexerErrorInterface lexer;
FileInputStream fis = new FileInputStream(smaliFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(smaliFile);
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
lexer = new smaliFlexLexer(reader);
LexerErrorInterface lexer = new smaliFlexLexer(reader);
((smaliFlexLexer)lexer).setSourceFile(smaliFile);
tokens = new CommonTokenStream((TokenSource)lexer);
CommonTokenStream tokens = new CommonTokenStream((TokenSource)lexer);
if (options.printTokens) {
tokens.getTokens();
@ -201,5 +199,10 @@ public class Smali {
dexGen.smali_file();
return dexGen.getNumberOfSyntaxErrors() == 0;
} finally {
if (fis != null) {
fis.close();
}
}
}
}