From 1b6e3792eca581953b9a110c543470c2a55c1f91 Mon Sep 17 00:00:00 2001 From: JowayWang Date: Wed, 6 Nov 2019 16:40:08 +0800 Subject: [PATCH 1/2] bugfix: fix memory leak when leave a room after socket close --- index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index aeb5b6e..28311ef 100644 --- a/index.js +++ b/index.js @@ -74,11 +74,12 @@ Adapter.prototype.addAll = function(id, rooms, fn){ */ Adapter.prototype.del = function(id, room, fn){ - this.sids[id] = this.sids[id] || {}; - delete this.sids[id][room]; - if (this.rooms.hasOwnProperty(room)) { - this.rooms[room].del(id); - if (this.rooms[room].length === 0) delete this.rooms[room]; + if (this.sids[id]) { + delete this.sids[id][room]; + if (this.rooms.hasOwnProperty(room)) { + this.rooms[room].del(id); + if (this.rooms[room].length === 0) delete this.rooms[room]; + } } if (fn) process.nextTick(fn.bind(null, null)); From 99dc43c1857a1f64de2d7bfd78b2a7aa4d9f5292 Mon Sep 17 00:00:00 2001 From: JowayWang Date: Wed, 6 Nov 2019 17:05:21 +0800 Subject: [PATCH 2/2] del room --- index.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 28311ef..f21dcbd 100644 --- a/index.js +++ b/index.js @@ -74,12 +74,11 @@ Adapter.prototype.addAll = function(id, rooms, fn){ */ Adapter.prototype.del = function(id, room, fn){ - if (this.sids[id]) { - delete this.sids[id][room]; - if (this.rooms.hasOwnProperty(room)) { - this.rooms[room].del(id); - if (this.rooms[room].length === 0) delete this.rooms[room]; - } + if (this.sids[id]) delete this.sids[id][room]; + + if (this.rooms.hasOwnProperty(room)) { + this.rooms[room].del(id); + if (this.rooms[room].length === 0) delete this.rooms[room]; } if (fn) process.nextTick(fn.bind(null, null));