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 <[email protected]>
---
 libsigrok/session.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libsigrok/session.c b/libsigrok/session.c
index 69b3321..9ffdfd4 100644
--- a/libsigrok/session.c
+++ b/libsigrok/session.c
@@ -82,8 +82,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? */
 
@@ -95,6 +94,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?
  *
@@ -110,7 +115,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;
-- 
1.7.10


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to