Skip to content

dtype ffi segfault on linux #144

Description

@phronmophobic

On linux, I was able to reliably cause a segfault when using dt-ffi/define-library-interface. The crash seems to be caused by the calling a native function after its corresponding com.sun.jna.NatilveLibrary instance has been garbage collected.

The following will crash:

(dt-ffi/define-library-interface
    {:answer {:rettype :int32}}
    :libraries ["answer"])

(defn -main [& args]
  (println (answer))

  (while true
    (System/gc)
    (println (answer))
    (Thread/sleep 1000)))

Workaround: Holding a reference to the NativeLibrary instance prevents the crash:

;; hang on to lib instance
(def libanswer (com.sun.jna.NativeLibrary/getInstance "answer"))
(dt-ffi/define-library-interface
    {:answer {:rettype :int32}}
    :libraries ["answer"])

(defn -main [& args]
  (println (answer))

  (while true
    (System/gc)
    (println (answer))
    (Thread/sleep 1000)))

Instructions and code: https://github.com/phronmophobic/dtype-ffi-linux-repro/

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions