From 7145dcb47cb03739c0e564cefc3da60caf4be34a Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:28:19 -0700 Subject: [PATCH] ffi: free libuv error message on failed dlopen When uv_dlopen() fails, the error message it allocates is only released by uv_dlclose(). DynamicLibrary::Close() skips uv_dlclose() when the handle is null, so each failed ffi.dlopen() leaked the message. Call uv_dlclose() on the failure path, as DLib::Open() does. Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Assisted-by: claude:opus-5.5 PR-URL: https://github.com/nodejs/node/pull/67007 Fixes: https://github.com/nodejs/node/issues/67006 Reviewed-By: Daeyeon Jeong Reviewed-By: Paolo Insogna --- src/node_ffi.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/node_ffi.cc b/src/node_ffi.cc index afdc8f1fd36..42da08c0658 100644 --- a/src/node_ffi.cc +++ b/src/node_ffi.cc @@ -578,6 +578,8 @@ void DynamicLibrary::New(const FunctionCallbackInfo& args) { opened ? static_cast(lib->lib_.handle) : nullptr); if (!opened) { THROW_ERR_FFI_CALL_FAILED(env, "dlopen failed: %s", uv_dlerror(&lib->lib_)); + // Free the error message. Close() skips uv_dlclose() for a null handle. + uv_dlclose(&lib->lib_); return; } }