eelcocramer/node-gpsd — pull request #3 by sajacy (2014-02-17 18:53:24+00:00)
Title: Prevent leaked handlers.

This is an issue when repeatedly connecting and disconnecting on the same Listener.

I've debugged the source and found that this is because the `connect` and `disconnect` methods are not cleaning up old listeners.

Say we are sampling infrequently with this code:

```javascript
var listener = new gpsd.Listener();
listener.on("data", writeToDisk);

setInterval(function() {
listener.connect();
setTimeout(function() { listener.disconnect(); }, 1 * 1000);
}, 60*1000)
```

I get a warning after 10 intervals that there are more than 10 listeners on the serviceSocket.

This is due to the `this.serviceSocket.on('connect')` and `this.serviceSocket.on('close')` lines at [L116](../blob/master/lib/gpsd.js#L116) and [L126](../blob/master/lib/gpsd.js#L126).