Fix #1132 by passing segment IDs, not segment instances
authorSoeren Apel <soeren@apelpie.net>
Mon, 5 Mar 2018 22:45:46 +0000 (23:45 +0100)
committerSoeren Apel <soeren@apelpie.net>
Mon, 5 Mar 2018 22:45:46 +0000 (23:45 +0100)
commit7f894d958eb5221161f0c6f2abbb57d43bb6aae7
tree80b6c68c010c1850592579f0f91ccd9530bf9bcc
parenta66e286e0276186c41b7ce07cfcbd0c4da2ca1cb
Fix #1132 by passing segment IDs, not segment instances

Passing segment instances fails because this creates a race condition.
When a long conversion is taking place, the SignalBase::samples_added
signal is called often but since it's in a separate thread, the calls
are queued and aren't executed immediately. Now if the conversion is
restarted - for example as a result of a changed conversion threshold -
then the segments holding the converted data are destroyed, rendering
the pointers submitted as parameters to samples_added invalid.

Once the signal queue is processed, those invalid pointers will be
accessed and PV segfaults.

Since the signal queue can neither be emptied nor flushed, this
leaves only two sensible choices:
1) Signal samples_added less often, thereby reducing the chance of
signals being queued
2) Supply the segment ID instead of the segment instance as that's
essentially the only thing we currently care about - in fact, the
only user of samples_added (ViewBase::on_samples_added) uses the
instance to query only this

As #1 is only a band-aid and not a waterproof solution, I chose
to go with #2.
pv/data/signalbase.cpp
pv/data/signalbase.hpp
pv/views/viewbase.cpp
pv/views/viewbase.hpp