Skip to content

Commit 7941fda

Browse files
Anna Kocheshkovaiambmelt
authored andcommitted
Close resources after reading the config file. (#520)
* Close resources after read. * Warn instead of verbose
1 parent 8925680 commit 7941fda

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

msal/src/main/java/com/microsoft/identity/client/PublicClientApplication.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,23 @@ private static PublicClientApplicationConfiguration loadConfiguration(InputStrea
10661066
throw new IllegalArgumentException("Unable to open provided configuration file.", e);
10671067
}
10681068
}
1069+
finally {
1070+
try {
1071+
configStream.close();
1072+
} catch (IOException e) {
1073+
if (isDefaultConfiguration) {
1074+
com.microsoft.identity.common.internal.logging.Logger.warn(
1075+
TAG + "loadConfiguration",
1076+
"Unable to close default configuration file. This can cause memory leak."
1077+
);
1078+
} else {
1079+
com.microsoft.identity.common.internal.logging.Logger.warn(
1080+
TAG + "loadConfiguration",
1081+
"Unable to close provided configuration file. This can cause memory leak."
1082+
);
1083+
}
1084+
}
1085+
}
10691086

10701087
final String config = new String(buffer);
10711088
final Gson gson = getGsonForLoadingConfiguration();
@@ -1203,4 +1220,4 @@ public void onCancel() {
12031220
private OAuth2TokenCache<?, ?, ?> getOAuth2TokenCache() {
12041221
return initCommonCache(mPublicClientConfiguration.getAppContext());
12051222
}
1206-
}
1223+
}

0 commit comments

Comments
 (0)