Pebble: fix resource leak on app installation

This commit is contained in:
cpfeiffer 2016-12-29 01:29:28 +01:00
parent 0646eda646
commit a96a747119
1 changed files with 11 additions and 3 deletions

View File

@ -60,6 +60,10 @@ public class PBWInstallHandler implements InstallHandler {
installActivity.setInfoText("file not found"); installActivity.setInfoText("file not found");
installActivity.setInstallEnabled(false); installActivity.setInstallEnabled(false);
return; return;
} catch (IOException e) {
installActivity.setInfoText("error reading file");
installActivity.setInstallEnabled(false);
return;
} }
if (!mPBWReader.isValid()) { if (!mPBWReader.isValid()) {
@ -168,18 +172,22 @@ public class PBWInstallHandler implements InstallHandler {
} }
InputStream jsConfigFile = mPBWReader.getInputStreamFile("pebble-js-app.js"); InputStream jsConfigFile = mPBWReader.getInputStreamFile("pebble-js-app.js");
if (jsConfigFile != null) { if (jsConfigFile != null) {
outputFile = new File(destDir, app.getUUID().toString() + "_config.js");
try { try {
outputFile = new File(destDir, app.getUUID().toString() + "_config.js");
FileUtils.copyStreamToFile(jsConfigFile, outputFile); FileUtils.copyStreamToFile(jsConfigFile, outputFile);
} catch (IOException e) { } catch (IOException e) {
LOG.error("Failed to open output file: " + e.getMessage(), e); LOG.error("Failed to open output file: " + e.getMessage(), e);
} finally {
try {
jsConfigFile.close();
} catch (IOException e) {
}
} }
} }
} }
@Override
public boolean isValid() { public boolean isValid() {
// always pretend it is valid, as we can't know yet about hw/fw version // always pretend it is valid, as we can't know yet about hw/fw version
return true; return true;