# Segfault on exit

**URL:** <https://discourse.julialang.org/t/segfault-on-exit/19987>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 23, 2019, 2:46pm UTC](https://discourse.julialang.org/t/segfault-on-exit/19987 "2019-01-23T14:46:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oyamad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oyamad/32/6863_2.png) [@oyamad](https://discourse.julialang.org/u/oyamad)\
**Post date:** [January 23, 2019, 2:46pm UTC](https://discourse.julialang.org/t/segfault-on-exit/19987/1 "2019-01-23T14:46:48Z")

</div>

I have written some code that adds new functionalities to a Julia library that wraps a C library. The code executes fine, in that it generates outcomes as expected, but _on exit of Julia_ it leads to a segmentation fault with the following message (on OS X):

```julia
signal (11): Segmentation fault: 11
in expression starting at no file:0
_ZN4llvm16MetadataTracking7untrackEPvRNS_8MetadataE at /Applications/Julia-1.0.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm6MDNode17dropAllReferencesEv at /Applications/Julia-1.0.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm15LLVMContextImplD2Ev at /Applications/Julia-1.0.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
_ZN4llvm11LLVMContextD1Ev at /Applications/Julia-1.0.app/Contents/Resources/julia/lib/julia/libLLVM.dylib (unknown line)
__cxa_finalize_ranges at /usr/lib/system/libsystem_c.dylib (unknown line)
exit at /usr/lib/system/libsystem_c.dylib (unknown line)
jl_exit at /Users/osx/buildbot/slave/package_osx64/build/src/jl_uv.c:605
exit at ./initdefs.jl:28 [inlined]
exit at ./initdefs.jl:29
do_call at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:324
eval_stmt_value at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:363 [inlined]
eval_body at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:682
jl_interpret_toplevel_thunk_callback at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:806
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x11a11f07f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:815
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:805
jl_toplevel_eval_in at /Users/osx/buildbot/slave/package_osx64/build/src/builtins.c:622
eval at ./boot.jl:319
eval_user_input at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:85
macro expansion at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:117 [inlined]
#28 at ./task.jl:259
jl_apply at /Users/osx/buildbot/slave/package_osx64/build/src/./julia.h:1537 [inlined]
start_task at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:268
Allocations: 29249313 (Pool: 29243444; Big: 5869); GC: 54
Segmentation fault: 11

```

I would appreciate any guess about the cause of the segfault or any general suggestion about what kind of operation done in the code I should look at.

How to reproduce:

1. Check out [this PR](https://github.com/JuliaPolyhedra/LRSLib.jl/pull/30).

2. Go to the `LRSLib.jl/test` directory.

3. Run either

[Here](https://gist.github.com/oyamad/46014ee6ef257e09d333cddb30be0993)’s lldb’s output, in case it is helpful.

Segfault occurs both on 1.0.3 and 1.1.0.

```nohighlight
julia> versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

```

```nohighlight
julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, ivybridge)

```

---

<div class="post-metadata">

**Author:** ![oyamad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oyamad/32/6863_2.png) [@oyamad](https://discourse.julialang.org/u/oyamad)\
**Post date:** [January 30, 2019, 1:24pm UTC](https://discourse.julialang.org/t/segfault-on-exit/19987/2 "2019-01-30T13:24:28Z")

</div>

It turned out I had overlooked a certain set of memory allocation related calls in the C library to import to the Julia side. The code works fine now with that.
