Added a new variable to iio.Buffer stored in self._ctx, this is reference to a Context variable. This reference ensures that the Context outlives the buffer, if this is not the case a segmentation violation will occur when destroying the buffer.
Signed-off-by: Jonas Hansen <joha@gomspace.com>
diff --git a/bindings/python/iio.py b/bindings/python/iio.py
index b408eec..3ffe2a2 100644
--- a/bindings/python/iio.py
+++ b/bindings/python/iio.py
@@ -519,6 +519,10 @@
self._length = samples_count * device.sample_size
self._samples_count = samples_count
+ self._ctx = device.ctx()
+ # Holds a reference to the corresponding IIO Context. This ensures that
+ # every iio.Buffer object is destroyed before its corresponding IIO Context.
+
def __del__(self):
if self._buffer is not None:
_buffer_destroy(self._buffer)