From: Alexandru Gagniuc Date: Wed, 19 Dec 2012 10:15:18 +0000 (-0600) Subject: session.c: Remove all remaining sources on sr_session_stop X-Git-Tag: dsupstream~415 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f1f7e62d6df766f4a65d7854ae2dd745c623c863;p=libsigrok.git session.c: Remove all remaining sources on sr_session_stop Some sources may not be necessarily associated with a device. The best example is the anykey pollfd from sigrok-cli. sr_session_stop only removes sources associated with hardware devices via dev_acquisition_stop. Sources such as anykey are not removed, and thus session->num_sources will not get to 0. As a result, we may get into situations where the event loop enters an infinite state. To prevent this, all we have to do is remove any active sources that are still present after dev_acquisition_stop has been called for all devices. This fixes bug 14. --- diff --git a/session.c b/session.c index 6a4a3c99..9f8a4df7 100644 --- a/session.c +++ b/session.c @@ -362,6 +362,15 @@ SR_API int sr_session_stop(void) } } + /* + * Some sources may not be necessarily associated with a device. + * Those sources may still be present even after stopping all devices. + * We need to make sure all sources are removed, or we risk running the + * session in an infinite loop. + */ + while (session->num_sources) + sr_session_source_remove(session->sources[0].poll_object); + return SR_OK; }