Skip to content

ffi: failed dlopen() leaks the libuv error message #67006

Open

Description

@trivikr

Version

main

Platform

macOS

Subsystem

ffi

What steps will reproduce the bug?

import { dlopen } from 'node:ffi';

const path = '/nonexistent/' + 'x'.repeat(200) + '.dylib';
const run = (n) => {
  for (let i = 0; i < n; i++) {
    try { dlopen(path, {}); } catch {}
  }
};

run(1000);
globalThis.gc();
const before = process.memoryUsage().rss;

run(400000);
globalThis.gc();
console.log((process.memoryUsage().rss - before) / 400000, 'B/call');

Run with

node --no-warnings --expose-gc repro.mjs

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

A failed dlopen() should not hold on to native memory. RSS stays flat

14.45888 B/call

What do you see instead?

1042.55488 B/call

RSS goes up by about 1 KB for each failed call (60 -> 477 MB over 400k calls).

Additional information

No response

Activity

  1. self-assigned this
    on Oct 25, 2026
  2. added
    ffiIssues and PRs related to experimental Foreign Function Interface support.
    on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ffiIssues and PRs related to experimental Foreign Function Interface support.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions