Fix a small memory leak when requiring CommonJS modules (#12984)

This commit is contained in:
Jarred Sumner
2024-07-31 22:30:01 -07:00
committed by GitHub
parent 49ab4c147a
commit dc620ea837
8 changed files with 34 additions and 75 deletions

View File

@@ -430,7 +430,7 @@ extern "C" void Bun__onFulfillAsyncModule(
}
}
if (res->result.value.commonJSExportsLen) {
if (res->result.value.isCommonJSModule) {
auto created = Bun::createCommonJSModule(jsCast<Zig::GlobalObject*>(globalObject), specifierValue, res->result.value);
if (created.has_value()) {
JSSourceCode* code = JSSourceCode::create(vm, WTFMove(created.value()));
@@ -602,7 +602,7 @@ JSValue fetchCommonJSModule(
Bun__transpileFile(bunVM, globalObject, specifier, referrer, typeAttribute, res, false);
getSourceCodeStringForDeref();
if (res->success && res->result.value.commonJSExportsLen) {
if (res->success && res->result.value.isCommonJSModule) {
target->evaluate(globalObject, specifier->toWTFString(BunString::ZeroCopy), res->result.value);
RETURN_IF_EXCEPTION(scope, {});
RELEASE_AND_RETURN(scope, target);
@@ -774,7 +774,7 @@ static JSValue fetchESMSourceCode(
getSourceCodeStringForDeref();
}
if (res->success && res->result.value.commonJSExportsLen) {
if (res->success && res->result.value.isCommonJSModule) {
auto created = Bun::createCommonJSModule(globalObject, specifierJS, res->result.value);
if (created.has_value()) {