xorbit / node-aes-gcm

AES GCM module for node.js using OpenSSL
MIT License
34 stars 16 forks source link

Fix memory leak #8

Closed sopepos closed 6 years ago

sopepos commented 6 years ago

I fixed memory leak. (added 3 "delete[] xxx") Without this code, RSS increases while heap is stable.

xorbit commented 6 years ago

Hi,

Thanks much for spotting this, that was a bad bug!

After looking at your patch and investigating the code, I decided to solve this differently. Instead of Nan::CopyBuffer I'm now using Nan::NewBuffer. According to the Nan documentation, this takes care of calling free on the provided C++ buffer when the Node Buffer is garbage collected, and it saves an unnecessary buffer copy operation in the process.

According to my testing this solves the problem. Please let me know if it works as expected in your testing as well, and close this if it does.

sopepos commented 6 years ago

Thanks for fast update. I ran my test code with 0.2.4 for 1 hour and there's no memory leak. Great! 👍 I close this pull request.