# Seg fault when using event loop with IPC calls

**URL:** <https://mangoh.discourse.group/t/seg-fault-when-using-event-loop-with-ipc-calls/1063>\
**Category:** Uncategorized\
**Created:** [January 5, 2018, 7:45pm UTC](https://mangoh.discourse.group/t/seg-fault-when-using-event-loop-with-ipc-calls/1063 "2018-01-05T19:45:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/nick/32/1380_2.png) [@nick](https://mangoh.discourse.group/u/nick)\
**Post date:** [January 5, 2018, 7:45pm UTC](https://mangoh.discourse.group/t/seg-fault-when-using-event-loop-with-ipc-calls/1063/1 "2018-01-05T19:45:23Z")

</div>

Hello all,

We’re working on an app that listens for digital input changes and then records them with a timestamp. At a later time, a separate app makes IPC calls to retrieve this data and flush it out.

The code for this app can be found here: [https://github.com/nvandoorn/digitalInputs](https://github.com/nvandoorn/digitalInputs)

Every time the separate app makes a call to retrieve the data, the data retrieved is incorrect, and the digital inputs app seg faults immediately after finishing any of the IPC functions specified in `brnkl_digital.api`. As it stands, digital input values are stored in a fixed size, statically allocated array with no sanity checks. I understand that this is somewhat dangerous, however the plan for the future is to shift out old values to make room for new ones. For the time being we’ve been sure to test this with a low number of digital changes to avoid running out of memory.

This issue seems to go away when I comment out the contents of `digital_changeHandler` which leads me to believe this issue is caused by incorrect usage of the Legato event loop.

Anyone have any ideas on how to further debug this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [January 6, 2018, 4:39pm UTC](https://mangoh.discourse.group/t/seg-fault-when-using-event-loop-with-ipc-calls/1063/2 "2018-01-06T16:39:43Z")

</div>

Hi Nick,

I have a few ideas.

1. Run `logread -f` and then launch your apps. Set your apps to manual start for debugging to make it easier to capture clean logs.
2. Start the service app and make sure that `sdir list` doesn’t show any waiting clients
3. When you call `le_digitalX_AddChangeEventHandler()` an opaque “handle” is returned. Basically there are two things you can do with it. Pass it back to the `le_digitalX_RemoveChangeEventHandler()` function and check the value against `NULL`. If the handle is `NULL`, then the registration failed. Make sure that you log that failure or use `LE_FATAL()` so that it’s obvious if the registration fails.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/nick/32/1380_2.png) [@nick](https://mangoh.discourse.group/u/nick)\
**Post date:** [January 8, 2018, 7:52pm UTC](https://mangoh.discourse.group/t/seg-fault-when-using-event-loop-with-ipc-calls/1063/3 "2018-01-08T19:52:20Z")

</div>

Hey @dfrey,

Thanks for the suggestions. Turns out it’s related to something I was curious about in my [last post](http://mangoh.discourse.group/t/ipc-app-failing-to-build/1053/2).

Over the weekend I realized I was writing into an array without specifying the max size in the `.api` file. I added the max size specification and then received a compile time error for conflicting function definitions. I dug into the generated build files a bit and noticed the build system was automatically adding parameters for pointers to array sizes directly after each array pointer. After re-defining my functions to include these new pointers, everything seems to work as expected.

I must say, there was a decent amount to unravel here that wasn’t very obvious by reading the docs or sample apps (unless I missed something). Are the docs open sourced anywhere? I would be happy to spend sometime improving them. Additionally, I could open a pull request to include our example app in the MangOH repo if this is desirable.

Thanks again for the quick help!

---

<div class="post-metadata">

**Author:** ![milessmith](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@milessmith](https://mangoh.discourse.group/u/milessmith)\
**Post date:** [October 18, 2018, 1:05pm UTC](https://mangoh.discourse.group/t/seg-fault-when-using-event-loop-with-ipc-calls/1063/4 "2018-10-18T13:05:57Z")

</div>

thanks guys for help i also wanted to know this good to know.  
with regards  
miles smith  
[https://notepad.software/](https://notepad.software/) [vidmate](https://vidmate.onl/download/)
