forked from sdr/gr-osmosdr
bladerf: Fixed bug in cached device cleanup
A couple issues were present in bladerf_common::close, which caused entries in the _devs list (our "device cache") to not be removed. This would result in a stale device handle being used upon attempting to reopen the device. Two issues were associated with this bug: - The weak_ptr expired() conditional was incorrect; the logic was inverted. - The list item removal and iterator increment was done incorrectly and would result in a crash after the first item was fixed.
This commit is contained in:
parent
4e0a2c28e3
commit
542a3dbb2b
|
@ -75,14 +75,20 @@ bladerf_sptr bladerf_common:: get_cached_device(struct bladerf_devinfo devinfo)
|
||||||
return bladerf_sptr();
|
return bladerf_sptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is called when a bladerf_sptr hits a refcount of 0 */
|
||||||
void bladerf_common::close(void* dev)
|
void bladerf_common::close(void* dev)
|
||||||
{
|
{
|
||||||
boost::unique_lock<boost::mutex> lock(_devs_mutex);
|
boost::unique_lock<boost::mutex> lock(_devs_mutex);
|
||||||
|
|
||||||
std::list<boost::weak_ptr<struct bladerf> >::iterator it;
|
/* Prune expired entries from device cache */
|
||||||
for (it = _devs.begin(); it != _devs.end(); ++it)
|
std::list<boost::weak_ptr<struct bladerf> >::iterator it(_devs.begin());
|
||||||
if ( (*it).expired() == 0 )
|
while ( it != _devs.end() ) {
|
||||||
_devs.erase(it);
|
if ( (*it).expired() ) {
|
||||||
|
it = _devs.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bladerf_close((struct bladerf *)dev);
|
bladerf_close((struct bladerf *)dev);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue