-
which of the 2 c-code below are correct? or are they both wrong, and its something else?
void napiFinalize(
napi_env env,
void *finalize_data,
void *finalize_hint
) {
// this function will free <finalize_data>
free(finalize_data);
}
...
char *cstring = malloc(256);
napi_value result;
napi_create_external_arraybuffer(
env,
(void *) cstring,
256,
napiFinalize, // explicitly free <cstring> when object is gc'd
NULL,
&result
);
return result;
char *cstring = malloc(256);
napi_value result;
napi_create_external_arraybuffer(
env,
(void *) cstring,
256,
NULL, // assume nodejs will automatically free <cstring>
NULL,
&result
);
return result; i'm troubleshooting an addon in win32 environment, that exits silently after a c-call (no segfault or loud warnings). a definitive answer to above might help diagnosing the bug. |
Beta Was this translation helpful? Give feedback.
Answered by
kaizhu256
Aug 25, 2021
Replies: 1 comment
-
nevermind, turns out option1 is correct (user needs to manually garbage collect with the silent-exit bug was due to something else -- cstring was realloc'd but forgot to set it to new pointer. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mhdawson
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nevermind, turns out option1 is correct (user needs to manually garbage collect with
free()
).the silent-exit bug was due to something else -- cstring was realloc'd but forgot to set it to new pointer.