1 | List iterators can become invalidated by executing on them. |
---|
2 | |
---|
3 | From: Erik Hovland <erik@hovland.org> |
---|
4 | |
---|
5 | If they are then used in testing they may behave correctly. But |
---|
6 | it is likely that the behavior is undefined and the invalidated |
---|
7 | iterator can actually cause a segfault if accessed. |
---|
8 | |
---|
9 | This patch addresses an instance where a iterator is invalidated |
---|
10 | and is then tested. |
---|
11 | --- |
---|
12 | |
---|
13 | libs/libmythtv/firewiredevice.cpp | 7 +++---- |
---|
14 | 1 files changed, 3 insertions(+), 4 deletions(-) |
---|
15 | |
---|
16 | diff --git a/libs/libmythtv/firewiredevice.cpp b/libs/libmythtv/firewiredevice.cpp |
---|
17 | index 52f7f9c..8abda84 100644 |
---|
18 | --- a/libs/libmythtv/firewiredevice.cpp |
---|
19 | +++ b/libs/libmythtv/firewiredevice.cpp |
---|
20 | @@ -49,13 +49,12 @@ void FirewireDevice::RemoveListener(TSDataListener *listener) |
---|
21 | { |
---|
22 | vector<TSDataListener*>::iterator it = m_listeners.end(); |
---|
23 | |
---|
24 | - do |
---|
25 | + for (it = find(m_listeners.begin(), m_listeners.end(), listener); |
---|
26 | + it != m_listeners.end();) |
---|
27 | { |
---|
28 | + m_listeners.erase(it); |
---|
29 | it = find(m_listeners.begin(), m_listeners.end(), listener); |
---|
30 | - if (it != m_listeners.end()) |
---|
31 | - m_listeners.erase(it); |
---|
32 | } |
---|
33 | - while (it != m_listeners.end()); |
---|
34 | |
---|
35 | VERBOSE(VB_RECORD, LOC + "RemoveListener() "<<m_listeners.size()); |
---|
36 | } |
---|