@@ -1673,7 +1673,11 @@ inline Function Function::New(napi_env env,
16731673 CbData::Wrapper,
16741674 callbackData,
16751675 &value);
1676- NAPI_THROW_IF_FAILED (env, status, Function ());
1676+ if (status != napi_ok) {
1677+ delete callbackData;
1678+ NAPI_THROW_IF_FAILED (env, status, Function ());
1679+ }
1680+
16771681 return Function (env, value);
16781682}
16791683
@@ -2636,7 +2640,10 @@ PropertyDescriptor::Accessor(Napi::Env env,
26362640 auto callbackData = new CbData ({ getter, data });
26372641
26382642 napi_status status = AttachData (env, object, callbackData);
2639- NAPI_THROW_IF_FAILED (env, status, napi_property_descriptor ());
2643+ if (status != napi_ok) {
2644+ delete callbackData;
2645+ NAPI_THROW_IF_FAILED (env, status, napi_property_descriptor ());
2646+ }
26402647
26412648 return PropertyDescriptor ({
26422649 utf8name,
@@ -2671,7 +2678,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
26712678 auto callbackData = new CbData ({ getter, data });
26722679
26732680 napi_status status = AttachData (env, object, callbackData);
2674- NAPI_THROW_IF_FAILED (env, status, napi_property_descriptor ());
2681+ if (status != napi_ok) {
2682+ delete callbackData;
2683+ NAPI_THROW_IF_FAILED (env, status, napi_property_descriptor ());
2684+ }
26752685
26762686 return PropertyDescriptor ({
26772687 nullptr ,
@@ -2697,7 +2707,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
26972707 auto callbackData = new CbData ({ getter, setter, data });
26982708
26992709 napi_status status = AttachData (env, object, callbackData);
2700- NAPI_THROW_IF_FAILED (env, status, napi_property_descriptor ());
2710+ if (status != napi_ok) {
2711+ delete callbackData;
2712+ NAPI_THROW_IF_FAILED (env, status, napi_property_descriptor ());
2713+ }
27012714
27022715 return PropertyDescriptor ({
27032716 utf8name,
@@ -2734,7 +2747,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
27342747 auto callbackData = new CbData ({ getter, setter, data });
27352748
27362749 napi_status status = AttachData (env, object, callbackData);
2737- NAPI_THROW_IF_FAILED (env, status, napi_property_descriptor ());
2750+ if (status != napi_ok) {
2751+ delete callbackData;
2752+ NAPI_THROW_IF_FAILED (env, status, napi_property_descriptor ());
2753+ }
27382754
27392755 return PropertyDescriptor ({
27402756 nullptr ,
0 commit comments