High severityNVD Advisory· Published Aug 31, 2021· Updated Aug 4, 2024
Missing Release of Memory after Effective Lifetime in detect-character-encoding
CVE-2021-39176
Description
detect-character-encoding is a package for detecting character encoding using ICU. In detect-character-encoding v0.3.0 and earlier, allocated memory is not released. The problem has been patched in detect-character-encoding v0.3.1.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
detect-character-encodingnpm | < 0.3.1 | 0.3.1 |
Affected products
1- Range: < 0.3.1
Patches
1d44356927b92Fix memory leak by properly closing `charsetDetector`
1 file changed · +5 −0
icuWrapper.cpp+5 −0 modified@@ -28,27 +28,31 @@ NAN_METHOD(DetectCharacterEncoding) { if(U_FAILURE(errorCode)) { Nan::ThrowError("Failed to set ICU charset detector’s text."); + ucsdet_close(charsetDetector); return; } charsetMatch = ucsdet_detect(charsetDetector, &errorCode); if(U_FAILURE(errorCode)) { Nan::ThrowError("Failed to detect charset."); + ucsdet_close(charsetDetector); return; } const char *charsetName = ucsdet_getName(charsetMatch, &errorCode); if(U_FAILURE(errorCode)) { Nan::ThrowError("Failed to get name from charset match."); + ucsdet_close(charsetDetector); return; } int32_t confidence = ucsdet_getConfidence(charsetMatch, &errorCode); if(U_FAILURE(errorCode)) { Nan::ThrowError("Failed to get confidence from charset match."); + ucsdet_close(charsetDetector); return; } @@ -57,6 +61,7 @@ NAN_METHOD(DetectCharacterEncoding) { obj->Set(Nan::New<v8::String>("confidence").ToLocalChecked(), Nan::New<v8::Number>(confidence)); info.GetReturnValue().Set(obj); + ucsdet_close(charsetDetector); } void Init(v8::Local<v8::Object> exports) {
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
6- github.com/advisories/GHSA-5rwj-j5m3-3chjghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-39176ghsaADVISORY
- github.com/sonicdoe/detect-character-encoding/commit/d44356927b92e3b13e178071bf6d7c671766f588ghsax_refsource_MISCWEB
- github.com/sonicdoe/detect-character-encoding/pull/6ghsax_refsource_MISCWEB
- github.com/sonicdoe/detect-character-encoding/releases/tag/v0.3.1ghsax_refsource_MISCWEB
- github.com/sonicdoe/detect-character-encoding/security/advisories/GHSA-5rwj-j5m3-3chjghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.