[blivet][master][PATCH] Do not alter the ParentList being iterated over (#1083581)

Martin Kolman mkolman at redhat.com
Tue May 27 14:36:50 UTC 2014


Vratislav Podzimek píše v Út 27. 05. 2014 v 16:29 +0200:
> Removing items from a list that is being iterated over may result in various
> weird, unexpected and hard to track issues (see rhbz#1083581 and rhbz#1083581).
> 
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
>  blivet/devices.py | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/blivet/devices.py b/blivet/devices.py
> index 787fbb5..cdd0642 100644
> --- a/blivet/devices.py
> +++ b/blivet/devices.py
> @@ -296,7 +296,9 @@ class Device(util.ObjectID):
>              self._parents = ParentList(appendfunc=self._addParent,
>                                         removefunc=self._removeParent)
>  
> -        for parent in self._parents:
> +        # iterate over a copy of the parent list because we are altering it in
> +        # the for-cycle
> +        for parent in list(self._parents):
>              self._parents.remove(parent)
>  
>      def _setParentList(self, parents):
Well, DOH! Looks good to me. :)



More information about the anaconda-patches mailing list