mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: https://github.com/nodejs/node-addon-api/pull/663 PR-URL: https://github.com/nodejs/node/pull/31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
12 lines
282 B
C
12 lines
282 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#define NAPI_EXPERIMENTAL
|
|
#include <node_api.h>
|
|
|
|
napi_value addon_new(napi_env env, napi_value exports, bool ref_first);
|
|
|
|
// static napi_value
|
|
NAPI_MODULE_INIT(/*napi_env env, napi_value exports */) {
|
|
return addon_new(env, exports, true);
|
|
}
|