ibmruntimes / vsam.js

Reading and writing vsam files using NodeJS
Apache License 2.0
10 stars 5 forks source link

fix memory leaks when errors occur #29

Closed gabylb closed 9 months ago

gabylb commented 9 months ago

When an error (e.g. "unexpected data type") is detected, uv_queue_work() doesn't get called (as intended) and therefore memory in recbuf and pFieldsToUpdate_ don't get freed (by the UvWorkData destructor) as no callback function (that destroys the UvWorkData object), gets called - causing memory leak.

gabylb commented 9 months ago

LGTM. Longer term, I wonder if a cleaner solution would be to use a unique_ptr (https://en.cppreference.com/w/cpp/memory/unique_ptr) so that it frees when it goes out of scope

In all cases here, those pointers are stored in UvWorkData and used by other functions, as operations in this module are placed in a message queue and accessed by a separate thread that executes them, after which the callback functions get called and destroys the object that contains them.