Skip to content

Commit

Permalink
src: fix callbackData leaks on error napi status
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node-addon-api#417
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
kevindavies8 committed Jan 2, 2019
1 parent ce332e7 commit 5655d67
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,11 @@ inline Function Function::New(napi_env env,
CbData::Wrapper,
callbackData,
&value);
NAPI_THROW_IF_FAILED(env, status, Function());
if (status != napi_ok) {
delete callbackData;
NAPI_THROW_IF_FAILED(env, status, Function());
}

return Function(env, value);
}

Expand Down Expand Up @@ -2636,7 +2640,10 @@ PropertyDescriptor::Accessor(Napi::Env env,
auto callbackData = new CbData({ getter, data });

napi_status status = AttachData(env, object, callbackData);
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
if (status != napi_ok) {
delete callbackData;
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
}

return PropertyDescriptor({
utf8name,
Expand Down Expand Up @@ -2671,7 +2678,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
auto callbackData = new CbData({ getter, data });

napi_status status = AttachData(env, object, callbackData);
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
if (status != napi_ok) {
delete callbackData;
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
}

return PropertyDescriptor({
nullptr,
Expand All @@ -2697,7 +2707,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
auto callbackData = new CbData({ getter, setter, data });

napi_status status = AttachData(env, object, callbackData);
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
if (status != napi_ok) {
delete callbackData;
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
}

return PropertyDescriptor({
utf8name,
Expand Down Expand Up @@ -2734,7 +2747,10 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
auto callbackData = new CbData({ getter, setter, data });

napi_status status = AttachData(env, object, callbackData);
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
if (status != napi_ok) {
delete callbackData;
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
}

return PropertyDescriptor({
nullptr,
Expand Down

0 comments on commit 5655d67

Please sign in to comment.