Patch by Sjoerd Mullender to placate /F:

Fix leaking of instances by removing the elements variable that we
created on closing the parser.  The elements variable is now created
in the reset() method, so that the sequence close(); reset();
... works.
Also, add the name of the entity reference that wasn't found to the
error message.
diff --git a/Lib/xmllib.py b/Lib/xmllib.py
index b87d540..92b55b7 100644
--- a/Lib/xmllib.py
+++ b/Lib/xmllib.py
@@ -88,11 +88,11 @@
 
     # Interface -- initialize and reset this instance
     def __init__(self):
+        self.__fixed = 0
         self.reset()
-        if self.elements is XMLParser.elements:
-            self.__fixelements()
 
     def __fixelements(self):
+        self.__fixed = 1
         self.elements = {}
         self.__fixdict(self.__dict__)
         self.__fixclass(self.__class__)
@@ -127,6 +127,10 @@
         self.__seen_starttag = 0
         self.__use_namespaces = 0
         self.__namespaces = {'xml':None}   # xml is implicitly declared
+        # backward compatipibility hack: if elements not overridden,
+        # fill it in ourselves
+        if self.elements is XMLParser.elements:
+            self.__fixelements()
 
     # For derived classes only -- enter literal mode (CDATA) till EOF
     def setnomoretags(self):
@@ -147,6 +151,10 @@
     # Interface -- handle the remaining data
     def close(self):
         self.goahead(1)
+        if self.__fixed:
+            self.__fixed = 0
+            # remove self.elements so that we don't leak
+            del self.elements
 
     # Interface -- translate references
     def translate_references(self, data, all = 1):
@@ -179,7 +187,7 @@
                     data = pre + self.entitydefs[str] + post
                     i = res.start(0)    # rescan substituted text
                 else:
-                    self.syntax_error('reference to unknown entity')
+                    self.syntax_error("reference to unknown entity `&%s;'" % str)
                     # can't do it, so keep the entity ref in
                     data = pre + '&' + str + ';' + post
                     i = res.start(0) + len(str) + 2
@@ -327,7 +335,7 @@
                         n = len(rawdata)
                         i = res.start(0)
                     else:
-                        self.syntax_error('reference to unknown entity')
+                        self.syntax_error("reference to unknown entity `&%s;'" % name)
                         self.unknown_entityref(name)
                     self.lineno = self.lineno + string.count(res.group(0), '\n')
                     continue