Skip to content

Commit 91eaa6f

Browse files
DaAitchmhdawson
authored andcommitted
src: fix callbackData leaks on error napi status
PR-URL: #417 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 0b40275 commit 91eaa6f

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

napi-inl.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)