Skip to content

Commit

Permalink
Channel could be registered more than once - leading to a mem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed Mar 2, 2012
1 parent 8b644bc commit b1bc1f6
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions examples/multiplex/multiplex_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ exports.MultiplexServer = MultiplexServer = function(service) {

conn.on('data', function(message) {
var t = message.split(',', 3);
var type = t[0], topic = t[1], payload = t[2];
var type = t[0], topic = t[1], payload = t[2];
if (!(topic in that.registered_channels)) {
return;
}
switch(type) {
case 'sub':
var sub = channels[topic] = new Channel(conn, topic,
channels);
that.registered_channels[topic].emit('connection', sub)
break;
case 'uns':
if (topic in channels) {
if (topic in channels) {
switch(type) {
case 'uns':
delete channels[topic];
channels[topic].emit('close');
}
break;
case 'msg':
if (topic in channels) {
break;
case 'msg':
channels[topic].emit('data', payload);
break;
}
} else {
switch(type) {
case 'sub':
var sub = channels[topic] = new Channel(conn, topic,
channels);
that.registered_channels[topic].emit('connection', sub)
break;
}
break;
}
});
conn.on('close', function() {
Expand Down

0 comments on commit b1bc1f6

Please sign in to comment.