fix listener leaks (#17913)

* fix listener leaks

* add null check

* simplify

* pr comments
This commit is contained in:
Alan Ren
2021-12-14 13:35:00 -08:00
committed by GitHub
parent 2b1acbc2c7
commit 970fe12e70
7 changed files with 59 additions and 43 deletions

View File

@@ -13,6 +13,7 @@ import { generateUuid } from 'vs/base/common/uuid';
import * as nls from 'vs/nls';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { deepClone } from 'vs/base/common/objects';
import { isDisposable } from 'vs/base/common/lifecycle';
export const GROUPS_CONFIG_KEY = 'datasource.connectionGroups';
export const CONNECTIONS_CONFIG_KEY = 'datasource.connections';
@@ -99,8 +100,10 @@ export class ConnectionConfig {
// Remove the profile if already set
let sameProfileInList = profiles.find(value => {
let providerConnectionProfile = ConnectionProfile.createFromStoredProfile(value, this._capabilitiesService);
return matcher(providerConnectionProfile, connectionProfile);
const providerConnectionProfile = ConnectionProfile.createFromStoredProfile(value, this._capabilitiesService);
const match = matcher(providerConnectionProfile, connectionProfile);
providerConnectionProfile.dispose();
return match;
});
if (sameProfileInList) {
let profileIndex = profiles.findIndex(value => value === sameProfileInList);
@@ -111,7 +114,14 @@ export class ConnectionConfig {
profiles.push(newProfile);
}
return this.configurationService.updateValue(CONNECTIONS_CONFIG_KEY, profiles, ConfigurationTarget.USER).then(() => connectionProfile);
return this.configurationService.updateValue(CONNECTIONS_CONFIG_KEY, profiles, ConfigurationTarget.USER).then(() => {
profiles.forEach(p => {
if (isDisposable(p)) {
p.dispose();
}
});
return connectionProfile;
});
});
} else {
return Promise.resolve(profile);