Skip to content

Commit

Permalink
Coverity Fixes - High
Browse files Browse the repository at this point in the history
Fix 2 theoretical resource leaks identified by Coverity Scan.

DbSQL.java and SSLContextManager.java one occurrence each.
  • Loading branch information
kingthorin committed Jan 31, 2017
1 parent 2f1437e commit 2ede9be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/ch/csnc/extension/httpclient/SSLContextManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,12 @@ public int loadPKCS12Certificate(String filename, String ksPassword)
String name = file.getName();

// Open the file
InputStream is = new FileInputStream(file);

// create the keystore
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(is, ksPassword == null ? null : ksPassword.toCharArray());

return addKeyStore(ks, "PKCS#12: " + name, ksPassword);
try (InputStream is = new FileInputStream(file)) {
// create the keystore
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(is, ksPassword == null ? null : ksPassword.toCharArray());
return addKeyStore(ks, "PKCS#12: " + name, ksPassword);
}
}

public boolean unlockKeyWithDefaultPassword(int keystoreIndex, int aliasIndex)
Expand Down
9 changes: 4 additions & 5 deletions src/org/zaproxy/zap/db/sql/DbSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,16 @@ public synchronized Database initDatabase() throws IllegalStateException, IOExce
throw new FileNotFoundException(file.getAbsolutePath());
}

Reader reader = new FileReader(file );
dbProperties = new Properties();
dbProperties.load(reader);

try (Reader reader = new FileReader(file )) {
dbProperties.load(reader);
}
dbType = dbProperties.getProperty("db.type");

// Load the SQL properties
sqlProperties = new Properties();
File sqlFile = new File (Constant.getZapInstall() + File.separator + "db", dbType + ".properties");
try {
Reader sqlReader = new FileReader(sqlFile);
try (Reader sqlReader = new FileReader(sqlFile)){
sqlProperties.load(sqlReader);
} catch (Exception e) {
logger.error("No SQL properties file for db type " + sqlFile.getAbsolutePath());
Expand Down

0 comments on commit 2ede9be

Please sign in to comment.