From 4719023f5fe08d5e16c0d8838837f76b36743cbd Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:18:28 -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 --- src/node_ffi.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/node_ffi.cc b/src/node_ffi.cc index fe110eeae8e..d6c50757f4f 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; } }