From b30b63666ddb4a753df52fa51d8cd6f1fe905845 Mon Sep 17 00:00:00 2001 From: Keijo Kapp Date: Tue, 28 May 2024 23:36:02 +0300 Subject: [PATCH] Fixed memory leaks in watches and callback API-s --- src/future.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/future.cpp b/src/future.cpp index 943c3d5..0c6fc4d 100644 --- a/src/future.cpp +++ b/src/future.cpp @@ -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). @@ -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));