@@ -1673,7 +1673,11 @@ inline Function Function::New(napi_env env,
1673
1673
CbData::Wrapper,
1674
1674
callbackData,
1675
1675
&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
+
1677
1681
return Function (env, value);
1678
1682
}
1679
1683
@@ -2636,7 +2640,10 @@ PropertyDescriptor::Accessor(Napi::Env env,
2636
2640
auto callbackData = new CbData ({ getter, data });
2637
2641
2638
2642
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
+ }
2640
2647
2641
2648
return PropertyDescriptor ({
2642
2649
utf8name,
@@ -2671,7 +2678,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
2671
2678
auto callbackData = new CbData ({ getter, data });
2672
2679
2673
2680
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
+ }
2675
2685
2676
2686
return PropertyDescriptor ({
2677
2687
nullptr ,
@@ -2697,7 +2707,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
2697
2707
auto callbackData = new CbData ({ getter, setter, data });
2698
2708
2699
2709
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
+ }
2701
2714
2702
2715
return PropertyDescriptor ({
2703
2716
utf8name,
@@ -2734,7 +2747,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
2734
2747
auto callbackData = new CbData ({ getter, setter, data });
2735
2748
2736
2749
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
+ }
2738
2754
2739
2755
return PropertyDescriptor ({
2740
2756
nullptr ,
0 commit comments