diff --git a/src/matrix/e2ee/Account.js b/src/matrix/e2ee/Account.js index 0478112b..e5c03cbd 100644 --- a/src/matrix/e2ee/Account.js +++ b/src/matrix/e2ee/Account.js @@ -126,8 +126,24 @@ export class Account { createInboundOlmSession(senderKey, body) { const newSession = new this._olm.Session(); - newSession.create_inbound_from(this._account, senderKey, body); - return newSession; + try { + newSession.create_inbound_from(this._account, senderKey, body); + return newSession; + } catch (err) { + newSession.free(); + throw err; + } + } + + createOutboundOlmSession(theirIdentityKey, theirOneTimeKey) { + const newSession = new this._olm.Session(); + try { + newSession.create_outbound_from(this._account, theirIdentityKey, theirOneTimeKey); + return newSession; + } catch (err) { + newSession.free(); + throw err; + } } writeRemoveOneTimeKey(session, txn) {