IrcServer memory leak fix
authorDarren <darren@darrenwhitlen.com>
Thu, 31 Jan 2013 14:28:18 +0000 (14:28 +0000)
committerDarren <darren@darrenwhitlen.com>
Thu, 31 Jan 2013 14:58:45 +0000 (14:58 +0000)
server/irc/eventbinder.js
server/irc/server.js

index e3d6d1b207b7e8ade18cf791c8dc0fc410d3e00f..aae2d2e9fca15f36660ee089c7edf13edc10df13 100644 (file)
@@ -15,7 +15,7 @@ module.exports.bindIrcEvents = function (events_scope, event_map, context, irc_c
 
         // Bind the event to `context`, storing it with the event listing
         if (!event_map._bound_events[event_name]) {
-            event_map._bound_events[event_name] = fn.bind(context);
+            event_map._bound_events[event_name] = _.bind(fn, context);
         }
 
         // Add the listener to the IRC connection object
@@ -40,7 +40,9 @@ module.exports.unbindIrcEvents = function (events_scope, event_map, irc_connecti
             irc_connection.removeListener(namespace_prefix + event_name, event_map._bound_events[event_name]);
 
             // Remove the bound function as no longer needed
-            event_map._bound_events[event_name] = undefined;
+            delete event_map._bound_events[event_name];
         }
     });
+
+    delete event_map._bound_events;
 };
\ No newline at end of file
index 2478e202a85b1b4c29d54e07409f4f66c7aca152..d7498460d2c8adfb2a81ffb0ca81b6cf6ea744b2 100755 (executable)
@@ -19,7 +19,7 @@ var IrcServer = function (irc_connection, host, port) {
         motd_start:             onMotdStart,
         motd:                   onMotd,
         motd_end:               onMotdEnd,
-        error:                  onError_,
+        error:                  onError,
         password_mismatch:      onPasswordMismatch,
         channel_redirect:       onChannelRedirect,
         no_such_nick:           onNoSuchNick,
@@ -118,7 +118,7 @@ function onMotdEnd(event) {
     });
 };
 
-function onError_(event) {
+function onError(event) {
     this.irc_connection.clientEvent('irc_error', {
         error: 'error',
         reason: event.reason