Skip to content

Commit

Permalink
Prevent dispose cycles
Browse files Browse the repository at this point in the history
For #75304

Make sure we do not get into a loop of tyring to dispose of an object by checking `isDisposed` before calling into dispose again

Also log if you try to register a disposeable on itself
  • Loading branch information
mjbvz committed Jun 11, 2019
1 parent af39a4d commit 9c14fec
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/vs/base/common/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export class DisposableStore implements IDisposable {
* Any future disposables added to this object will be disposed of on `add`.
*/
public dispose(): void {
if (this._isDisposed) {
return;
}

markTracked(this);
this._isDisposed = true;
this.clear();
Expand All @@ -110,6 +114,9 @@ export class DisposableStore implements IDisposable {
if (!t) {
return t;
}
if ((t as any as DisposableStore) === this) {
throw new Error('Cannot register a disposable on itself!');
}

markTracked(t);
if (this._isDisposed) {
Expand Down Expand Up @@ -140,6 +147,9 @@ export abstract class Disposable implements IDisposable {
}

protected _register<T extends IDisposable>(t: T): T {
if ((t as any as Disposable) === this) {
throw new Error('Cannot register a disposable on itself!');
}
return this._store.add(t);
}
}
Expand Down

0 comments on commit 9c14fec

Please sign in to comment.