Skip to content

ffi: segfault when a signature getter closes the library in getFunction() #66367

Description

@trivikr

Version

main

Platform

macOS 26.7.0

Subsystem

ffi

What steps will reproduce the bug?

import { DynamicLibrary } from 'node:ffi';
const lib = new DynamicLibrary(process.argv[2]);

lib.getFunction('add_i32', { arguments: ['i32', 'i32'], return: 'i32' });
lib.getFunction('add_i32', {
  arguments: ['i32', 'i32'],
  get return() { lib.close(); return 'i32'; },
});

Run with node repro.js, using any shared library that exports add_i32 (for example, test/ffi/fixture_library)

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

Always

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

The second call should throw ERR_FFI_LIBRARY_CLOSED, the same error getFunction() throws on a closed library.

What do you see instead?

The process crashes with a segmentation fault (exit code 139).

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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