From 992779a534dcd4d9c75ab6c5242f186eda449477 Mon Sep 17 00:00:00 2001 From: Tim G L Lyons Date: Sun, 11 Dec 2011 21:18:29 +0000 Subject: [PATCH] 0005414: Crash in SourceView. LRU clear does not reset first and last pointers svn: r18579 --- src/Lru.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Lru.py b/src/Lru.py index fc8b31912..bf2191009 100644 --- a/src/Lru.py +++ b/src/Lru.py @@ -155,7 +155,25 @@ class LRU(object): """ Empties LRU """ - for obj, node in self.data.iteritems(): - node.prev = None - node.next = None + # Step through the doubly linked list, setting prev and next to None. + # This ensures that each node is unreachable and therefore eligible for + # garbage collection. "del" is also called for each node, but it is + # unclear whether this actually has any effect, of just removes the + # binding to nobj + nobj = self.first + # The references first and last are removed so that the nodes are not + # reachable from these + self.first = None + self.last = None + # The references from self.data are removed self.data.clear() + while nobj is not None and nobj.next is not None: + # each node except the last is processed + nobj.next.prev = None + nextobj = nobj.next + nobj.next = None + del nobj + nobj = nextobj + if nobj is not None: + # The last node is processed + del nobj