From fba5877b3bc5b9b079e3bfe22e8f04eab963815c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 18 Nov 2020 20:08:42 +0100 Subject: [PATCH] dispose attachment blobs when pending event is removed/closing session --- src/matrix/room/AttachmentUpload.js | 5 +++++ src/matrix/room/Room.js | 1 + src/matrix/room/sending/PendingEvent.js | 8 ++++++++ src/matrix/room/sending/SendQueue.js | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/src/matrix/room/AttachmentUpload.js b/src/matrix/room/AttachmentUpload.js index dc25ce16..a66fbd45 100644 --- a/src/matrix/room/AttachmentUpload.js +++ b/src/matrix/room/AttachmentUpload.js @@ -89,6 +89,11 @@ export class AttachmentUpload { setPath(`${prefix}url`, content, this._mxcUrl); } } + + dispose() { + this._unencryptedBlob.dispose(); + this._transferredBlob.dispose(); + } } function setPath(path, content, value) { diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index f2635492..4cf9106e 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -640,6 +640,7 @@ export class Room extends EventEmitter { dispose() { this._roomEncryption?.dispose(); this._timeline?.dispose(); + this._sendQueue.dispose(); } } diff --git a/src/matrix/room/sending/PendingEvent.js b/src/matrix/room/sending/PendingEvent.js index a1e906ae..550cde8d 100644 --- a/src/matrix/room/sending/PendingEvent.js +++ b/src/matrix/room/sending/PendingEvent.js @@ -152,4 +152,12 @@ export class PendingEvent { this._status = SendStatus.Sent; this._emitUpdate("status"); } + + dispose() { + if (this._attachments) { + for (const attachment of Object.values(this._attachments)) { + attachment.dispose(); + } + } + } } diff --git a/src/matrix/room/sending/SendQueue.js b/src/matrix/room/sending/SendQueue.js index aa3a29b9..4a678cfe 100644 --- a/src/matrix/room/sending/SendQueue.js +++ b/src/matrix/room/sending/SendQueue.js @@ -121,6 +121,7 @@ export class SendQueue { await txn.complete(); this._pendingEvents.remove(idx); } + pendingEvent.dispose(); } emitRemovals(pendingEvents) { @@ -129,6 +130,7 @@ export class SendQueue { if (idx !== -1) { this._pendingEvents.remove(idx); } + pendingEvent.dispose(); } } @@ -201,4 +203,10 @@ export class SendQueue { await txn.complete(); return pendingEvent; } + + dispose() { + for (const pe in this._pendingEvents.array) { + pe.dispose(); + } + } }