VYPR
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.

PackageAffected versionsPatched versions
detect-character-encodingnpm
< 0.3.10.3.1

Affected products

1

Patches

1
d44356927b92

Fix 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

News mentions

0

No linked articles in our index yet.