summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWu Cheng-Han2015-09-26 10:25:00 +0800
committerWu Cheng-Han2015-09-26 10:25:00 +0800
commit332413bcaa7e1c810f236239474d997eb5d1aa43 (patch)
tree4c80646a8cedc45f28a740cfd076f72371227e3a /lib
parent3683a6dd3421a7392d728d6dd33ea452380b2154 (diff)
Fixed if using splice in loop should always decrement index or might out of array range
Diffstat (limited to '')
-rw-r--r--lib/realtime.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/realtime.js b/lib/realtime.js
index 09da1c8c..23464099 100644
--- a/lib/realtime.js
+++ b/lib/realtime.js
@@ -264,8 +264,10 @@ function finishConnection(socket, note, user) {
//clear finished socket in queue
for (var i = 0; i < connectionSocketQueue.length; i++) {
- if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id)
+ if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id) {
connectionSocketQueue.splice(i, 1);
+ i--;
+ }
}
//seek for next socket
isConnectionBusy = false;
@@ -302,8 +304,10 @@ function startConnection(socket) {
socket.disconnect(true);
//clear err socket in queue
for (var i = 0; i < connectionSocketQueue.length; i++) {
- if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id)
+ if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id) {
connectionSocketQueue.splice(i, 1);
+ i--;
+ }
}
isConnectionBusy = false;
return logger.error(err);
@@ -390,8 +394,10 @@ function disconnect(socket) {
//clear finished socket in queue
for (var i = 0; i < disconnectSocketQueue.length; i++) {
- if (!disconnectSocketQueue[i] || disconnectSocketQueue[i].id == socket.id)
+ if (!disconnectSocketQueue[i] || disconnectSocketQueue[i].id == socket.id) {
disconnectSocketQueue.splice(i, 1);
+ i--;
+ }
}
//seek for next socket
isDisconnectBusy = false;