From: Lars-Peter Clausen Date: Thu, 5 Jul 2012 19:15:07 +0000 (+0200) Subject: sr: session: Close a device when it is removed from a session X-Git-Tag: dsupstream~867 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ed229aaa8ff66116967f75112be953940d4a3149;p=libsigrok.git sr: session: Close a device when it is removed from a session A device is opened when it is added to a session, in the same fashion it should be closed again when it is removed from a session. Also remove all still attached devices from a session when the session is destroyed. Signed-off-by: Lars-Peter Clausen --- diff --git a/session.c b/session.c index 8fde4bf3..0cd4e200 100644 --- a/session.c +++ b/session.c @@ -74,8 +74,7 @@ SR_API int sr_session_destroy(void) return SR_ERR_BUG; } - g_slist_free(session->devs); - session->devs = NULL; + sr_session_dev_remove_all(); /* TODO: Error checks needed? */ @@ -87,6 +86,12 @@ SR_API int sr_session_destroy(void) return SR_OK; } +static void sr_dev_close(struct sr_dev *dev) +{ + if (dev->driver->dev_close) + dev->driver->dev_close(dev->driver_index); +} + /** * Remove all the devices from the current session. TODO? * @@ -102,7 +107,7 @@ SR_API int sr_session_dev_remove_all(void) return SR_ERR_BUG; } - g_slist_free(session->devs); + g_slist_free_full(session->devs, (GDestroyNotify)sr_dev_close); session->devs = NULL; return SR_OK;