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;