Fix memory leak by properly closing charsetDetector #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Hi,
we detected a memory issue with the latest version of detect-character-encoding and found that the documentation of ucsdet_close specifically mentions:
(see: http://icu-project.org/apiref/icu4c/ucsdet_8h.html#a84dab4d2c56fedb624a01db170ba698c)
Close a charset detector. All storage and any other resources owned by this charset detector will be released. Failure to close a charset detector when finished with it can result in memory leaks in the application.
I tried my hand at fixing the issue. From what I could see, the code change fixed the leak.
Because Nan:ThrowError does not seem to break the execution order of the code in this file, and ucsdet_open returns a null pointer in case of failure, it ought to be enough to close the charsetDetector at the end if it is not a nullptr and therefore was created successfully.
Regards,
Michael