caseyjhol / node-red-contrib-tplink

A collection of Node-RED nodes for TP-Link Smart Home devices
https://www.npmjs.com/package/node-red-contrib-tplink-iot
MIT License
16 stars 15 forks source link

Fix memory leak caused by failure to properly close #32

Closed hufftheweevil closed 4 years ago

hufftheweevil commented 4 years ago

This fix checks to make sure the stopPolling and closeConnection methods actually exist before calling them. If the device is a placeholder (i.e. was never actually connected), and an attempt is made to call these non-existent methods, then it will cause an error. The error will be caught by node-red but will cause the entire node.on('close') event callback to cease and therefore any other devices will not be disconnected. Those still-connected devices will continue to poll, resulting in a memory leak. By checking to make sure these methods exist, it will prevent an error from occurring, thereby prevent a memory leak.