Skip to content

Commit

Permalink
Fixed memory leaks in watches and callback API-s (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
keijokapp authored May 28, 2024
1 parent 81304b8 commit e38beb9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/future.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ MaybeValue fdbFutureToCallback(napi_env env, FDBFuture *f, napi_value cbFunc, Ex
napi_value callback;
NAPI_OK_OR_RETURN_STATUS(env, napi_get_reference_value(env, ctx->cbFunc, &callback));
NAPI_OK_OR_RETURN_STATUS(env, napi_reference_unref(env, ctx->cbFunc, NULL));
NAPI_OK_OR_RETURN_STATUS(env, napi_delete_reference(env, ctx->cbFunc));

size_t argc = 1; // In case of error we just won't populate argv[1].
napi_value argv[2] = {}; // (err, value).
Expand Down Expand Up @@ -306,6 +307,7 @@ MaybeValue watchFuture(napi_env env, FDBFuture *f, bool ignoreStandardErrors) {
napi_value jsWatch;
NAPI_OK_OR_RETURN_STATUS(env, napi_get_reference_value(env, ctx->jsWatch, &jsWatch));
NAPI_OK_OR_RETURN_STATUS(env, napi_reference_unref(env, ctx->jsWatch, NULL));
NAPI_OK_OR_RETURN_STATUS(env, napi_delete_reference(env, ctx->jsWatch));

// Unlink the handle to the future.
NAPI_OK_OR_RETURN_STATUS(env, napi_remove_wrap(env, jsWatch, NULL));
Expand Down

0 comments on commit e38beb9

Please sign in to comment.