From bef12c7a8fdbbf16a65e657c5e0c7f6afefbc722 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 28 Oct 2021 11:48:25 +0200 Subject: [PATCH] prevent double free on olm account when logging out by ensuring we only dispose the e2ee/Account once, as well as the Session and other classes --- src/matrix/Session.js | 5 +++++ src/matrix/SessionContainer.js | 3 +++ src/matrix/e2ee/Account.js | 1 + src/matrix/e2ee/megolm/decryption/KeyLoader.ts | 1 + 4 files changed, 10 insertions(+) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 90f383bb..13dbc128 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -374,12 +374,17 @@ export class Session { dispose() { this._olmWorker?.dispose(); + this._olmWorker = undefined; this._sessionBackup?.dispose(); + this._sessionBackup = undefined; this._megolmDecryption.dispose(); + this._megolmDecryption = undefined; this._e2eeAccount?.dispose(); + this._e2eeAccount = undefined; for (const room of this._rooms.values()) { room.dispose(); } + this._rooms = undefined; } /** diff --git a/src/matrix/SessionContainer.js b/src/matrix/SessionContainer.js index 84d79bcb..9794e93a 100644 --- a/src/matrix/SessionContainer.js +++ b/src/matrix/SessionContainer.js @@ -384,12 +384,15 @@ export class SessionContainer { this._reconnector = null; if (this._requestScheduler) { this._requestScheduler.stop(); + this._requestScheduler = null; } if (this._sync) { this._sync.stop(); + this._sync = null; } if (this._session) { this._session.dispose(); + this._session = null; } if (this._waitForFirstSyncHandle) { this._waitForFirstSyncHandle.dispose(); diff --git a/src/matrix/e2ee/Account.js b/src/matrix/e2ee/Account.js index 81725dcc..13792ddc 100644 --- a/src/matrix/e2ee/Account.js +++ b/src/matrix/e2ee/Account.js @@ -311,5 +311,6 @@ export class Account { dispose() { this._account.free(); + this._account = undefined; } } diff --git a/src/matrix/e2ee/megolm/decryption/KeyLoader.ts b/src/matrix/e2ee/megolm/decryption/KeyLoader.ts index 58f968c8..3aca957d 100644 --- a/src/matrix/e2ee/megolm/decryption/KeyLoader.ts +++ b/src/matrix/e2ee/megolm/decryption/KeyLoader.ts @@ -212,6 +212,7 @@ class KeyOperation { dispose() { this.session.free(); + this.session = undefined as any; } /** returns whether the key for this operation has been checked at some point against storage