<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Hello Community,</p>
<p><br>
</p>
<p>I have developed an application for BLE using DBUS for Linux. It is working fine but sometimes I have seen seg fault. </p>
<p><br>
</p>
<p>My application has a single event loop thread for dbus (THREAD A). I have used glib event loop. It is exactly similar to "bluetoothctl" event loop implementation:
<a href="https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/gdbus/mainloop.c" class="OWAAutoLink" id="LPlnk962081" previewremoved="true">
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/gdbus/mainloop.c</a> . I using that thread for receiving signal and error dbus messages using filter callbacks (by using function "<span>dbus_connection_add_filter"</span>). I have set watch and timeout
handlers using glib implementation (by calling <span>dbus_connection_set_watch_functions, <span>dbus_connection_set_timeout_functions and <span>dbus_connection_set_dispatch_status_function</span></span></span>). You can check the above link as i have using
their code. </p>
<p><br>
</p>
<p class="">My main thread (THREAD B) calls dbus methods and block on pending call instance for replies. I am not sure whether there could be some race condition with current software architecture as I have seen seg fault and valgrind showed it was related
to invalid memory read and write in my timeout implementation. Unfortunately, I was not able to record the valgrind output and seg fault never occured after that. I just want to be sure I am doing it correctly so I won't see seg fault if I release my software.</p>
<p class=""><br>
</p>
<p class="flipthis-highlight">For example, THREAD B calls a dbus method and it has set a timeout for it. I will then block on it. The THREAD A may dispatch a timeout event if timeout has occurred. I am not completely sure but I think there could be some race
condition in this case. Please help me.</p>
<p class=""><br>
</p>
<p class="">Thanks</p>
</div>
</body>
</html>