Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak #1633

Merged
merged 1 commit into from
Aug 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public void setDelayLoadingLobs(boolean b) {
*/
public static synchronized void registerColumnEncryptionKeyStoreProviders(
Map<String, SQLServerColumnEncryptionKeyStoreProvider> clientKeyStoreProviders) throws SQLServerException {
loggerExternal.entering(loggingClassName, "registerColumnEncryptionKeyStoreProviders",
loggerExternal.entering(loggingClassNameBase, "registerColumnEncryptionKeyStoreProviders",
"Registering Column Encryption Key Store Providers");

if (null == clientKeyStoreProviders) {
Expand Down Expand Up @@ -883,7 +883,7 @@ public static synchronized void registerColumnEncryptionKeyStoreProviders(
globalCustomColumnEncryptionKeyStoreProviders.put(entry.getKey(), entry.getValue());
}

loggerExternal.exiting(loggingClassName, "registerColumnEncryptionKeyStoreProviders",
loggerExternal.exiting(loggingClassNameBase, "registerColumnEncryptionKeyStoreProviders",
"Number of Key store providers that are registered:"
+ globalCustomColumnEncryptionKeyStoreProviders.size());
}
Expand All @@ -893,15 +893,15 @@ public static synchronized void registerColumnEncryptionKeyStoreProviders(
* the map and setting it to null.
*/
public static synchronized void unregisterColumnEncryptionKeyStoreProviders() {
loggerExternal.entering(loggingClassName, "unregisterColumnEncryptionKeyStoreProviders",
loggerExternal.entering(loggingClassNameBase, "unregisterColumnEncryptionKeyStoreProviders",
"Removing Column Encryption Key Store Provider");

if (null != globalCustomColumnEncryptionKeyStoreProviders) {
globalCustomColumnEncryptionKeyStoreProviders.clear();
globalCustomColumnEncryptionKeyStoreProviders = null;
}

loggerExternal.exiting(loggingClassName, "unregisterColumnEncryptionKeyStoreProviders",
loggerExternal.exiting(loggingClassNameBase, "unregisterColumnEncryptionKeyStoreProviders",
"Number of Key store providers that are registered: 0");
}

Expand Down Expand Up @@ -978,7 +978,7 @@ synchronized SQLServerColumnEncryptionKeyStoreProvider getColumnEncryptionKeySto
*/
public static synchronized void setColumnEncryptionTrustedMasterKeyPaths(
Map<String, List<String>> trustedKeyPaths) {
loggerExternal.entering(loggingClassName, "setColumnEncryptionTrustedMasterKeyPaths",
loggerExternal.entering(loggingClassNameBase, "setColumnEncryptionTrustedMasterKeyPaths",
"Setting Trusted Master Key Paths");

// Use upper case for server and instance names.
Expand All @@ -987,7 +987,7 @@ public static synchronized void setColumnEncryptionTrustedMasterKeyPaths(
columnEncryptionTrustedMasterKeyPaths.put(entry.getKey().toUpperCase(), entry.getValue());
}

loggerExternal.exiting(loggingClassName, "setColumnEncryptionTrustedMasterKeyPaths",
loggerExternal.exiting(loggingClassNameBase, "setColumnEncryptionTrustedMasterKeyPaths",
"Number of Trusted Master Key Paths: " + columnEncryptionTrustedMasterKeyPaths.size());
}

Expand All @@ -1001,13 +1001,13 @@ public static synchronized void setColumnEncryptionTrustedMasterKeyPaths(
*/
public static synchronized void updateColumnEncryptionTrustedMasterKeyPaths(String server,
List<String> trustedKeyPaths) {
loggerExternal.entering(loggingClassName, "updateColumnEncryptionTrustedMasterKeyPaths",
loggerExternal.entering(loggingClassNameBase, "updateColumnEncryptionTrustedMasterKeyPaths",
"Updating Trusted Master Key Paths");

// Use upper case for server and instance names.
columnEncryptionTrustedMasterKeyPaths.put(server.toUpperCase(), trustedKeyPaths);

loggerExternal.exiting(loggingClassName, "updateColumnEncryptionTrustedMasterKeyPaths",
loggerExternal.exiting(loggingClassNameBase, "updateColumnEncryptionTrustedMasterKeyPaths",
"Number of Trusted Master Key Paths: " + columnEncryptionTrustedMasterKeyPaths.size());
}

Expand All @@ -1018,13 +1018,13 @@ public static synchronized void updateColumnEncryptionTrustedMasterKeyPaths(Stri
* String server name
*/
public static synchronized void removeColumnEncryptionTrustedMasterKeyPaths(String server) {
loggerExternal.entering(loggingClassName, "removeColumnEncryptionTrustedMasterKeyPaths",
loggerExternal.entering(loggingClassNameBase, "removeColumnEncryptionTrustedMasterKeyPaths",
"Removing Trusted Master Key Paths");

// Use upper case for server and instance names.
columnEncryptionTrustedMasterKeyPaths.remove(server.toUpperCase());

loggerExternal.exiting(loggingClassName, "removeColumnEncryptionTrustedMasterKeyPaths",
loggerExternal.exiting(loggingClassNameBase, "removeColumnEncryptionTrustedMasterKeyPaths",
"Number of Trusted Master Key Paths: " + columnEncryptionTrustedMasterKeyPaths.size());
}

Expand All @@ -1034,7 +1034,7 @@ public static synchronized void removeColumnEncryptionTrustedMasterKeyPaths(Stri
* @return columnEncryptionTrustedMasterKeyPaths.
*/
public static synchronized Map<String, List<String>> getColumnEncryptionTrustedMasterKeyPaths() {
loggerExternal.entering(loggingClassName, "getColumnEncryptionTrustedMasterKeyPaths",
loggerExternal.entering(loggingClassNameBase, "getColumnEncryptionTrustedMasterKeyPaths",
"Getting Trusted Master Key Paths");

Map<String, List<String>> masterKeyPathCopy = new HashMap<>();
Expand All @@ -1043,7 +1043,7 @@ public static synchronized Map<String, List<String>> getColumnEncryptionTrustedM
masterKeyPathCopy.put(entry.getKey(), entry.getValue());
}

loggerExternal.exiting(loggingClassName, "getColumnEncryptionTrustedMasterKeyPaths",
loggerExternal.exiting(loggingClassNameBase, "getColumnEncryptionTrustedMasterKeyPaths",
"Number of Trusted Master Key Paths: " + masterKeyPathCopy.size());

return masterKeyPathCopy;
Expand Down Expand Up @@ -1214,7 +1214,8 @@ final SQLCollation getDatabaseCollation() {
.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerConnection");
static final private java.util.logging.Logger loggerExternal = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.Connection");
private static String loggingClassName = "com.microsoft.sqlserver.jdbc.SQLServerConnection:";
private static String loggingClassNameBase = "com.microsoft.sqlserver.jdbc.SQLServerConnection";
private String loggingClassName = loggingClassNameBase;

/**
* There are three ways to get a failover partner connection string, from the failover map, the connecting server
Expand Down Expand Up @@ -1297,7 +1298,7 @@ final boolean attachConnId() {
SQLServerConnection(String parentInfo) throws SQLServerException {
int connectionID = nextConnectionID(); // sequential connection id
traceID = "ConnectionID:" + connectionID;
loggingClassName += connectionID;
loggingClassName += ":" + connectionID;
if (connectionlogger.isLoggable(Level.FINE))
connectionlogger.fine(toString() + " created by (" + parentInfo + ")");
initResettableValues();
Expand Down