# I am looking for some help with segfault when passing a struct to a C-API via \`@cc

**URL:** https://discourse.julialang.org/t/i-am-looking-for-some-help-with-segfault-when-passing-a-struct-to-a-c-api-via-cc/55425
**Category:** General Usage
**Created:** [February 16, 2021, 9:30pm UTC](https://discourse.julialang.org/t/i-am-looking-for-some-help-with-segfault-when-passing-a-struct-to-a-c-api-via-cc/55425 "2021-02-16T21:30:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)
#### Post date: [February 16, 2021, 9:30pm UTC](https://discourse.julialang.org/t/i-am-looking-for-some-help-with-segfault-when-passing-a-struct-to-a-c-api-via-cc/55425/1 "2021-02-16T21:30:32Z")

</div>

I am looking for some help with segfault when passing a struct to a C-API via `@ccall`. I created an immutable struct inside a `Ref()`, and then call something like `@ccall lib.somefunc(myref::Ptr{MyStruct})...`. This seems to work, but then when the Julia function returns I get an `EXCEPTION_ACCESS_VIOLATION at 0x2a088a9 -- jl_gc_pool_alloc`.

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1613511012469500?thread_ts=1613511012.469500&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

### Author: ![sefffal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sefffal/32/23640_2.png) [@sefffal](https://discourse.julialang.org/u/sefffal)
#### Post date: [February 16, 2021, 10:15pm UTC](https://discourse.julialang.org/t/i-am-looking-for-some-help-with-segfault-when-passing-a-struct-to-a-c-api-via-cc/55425/2 "2021-02-16T22:15:16Z")

</div>

Solved by @mkitti  
The struct I was passing in needed a buffer. I used a Julia array directly as a field in that struct, when in fact I needed to use `pointer(array)`.  
Thanks!
