• Andrés G. Aragoneses's avatar
    SourceMessage: fix race in access to actions collection (bgo#751582) · 7ad6e330
    Andrés G. Aragoneses authored
    This foreach() loop had the potential problem of a typical race
    throwing a 'System.InvalidOperationException: Collection was modified;
    enumeration operation may not execute.'
    
    The normal thing to do in these cases is just to make a copy of the
    collection (via the .ToArray() method, for instance), at the
    beginning of the loop. However, this approach alone:
    
    a) would have presented a new race between the check for null
    and the call to the ToArray method.
    b) wouldn't have worked at compile time because IEnumerable<X>
    doesn't have this method (List<X> does).
    
    The proper way to fix (a) involves also avoiding to have
    a null value. How? Initializing the field always at
    construction time of the SourceMessage class.
    
    This has the good side-effect of being able to remove all
    null-checks around this field and its wrapper property.
    
    WRT (b) we could have created a new list at the beginning
    of the foreach loop, but it's more practical to just do the
    copy in the SourceMessage class, because, in the end, a read
    access should also involve lock()ing, otherwise writers to
    the collection could race with the readers of it.
    7ad6e330
Name
Last commit
Last update
..
Backends Loading commit data...
Clients Loading commit data...
Core Loading commit data...
Dap Loading commit data...
Extensions Loading commit data...
Hyena @ 229d3e81 Loading commit data...
Libraries Loading commit data...
AssemblyInfo.cs.in Loading commit data...
Makefile.am Loading commit data...
create-extension Loading commit data...
generate-dbus-docs Loading commit data...
nuke-core-tables Loading commit data...
nuke-dev-keys Loading commit data...
nuke-gconf-keys Loading commit data...
run-banshee Loading commit data...