xmlSchemaValidCtxtPtr reuse memory leak
When reusing an xmlSchemaValidCtxtPtr to validate multiple xml documents against the same schema, there is a memory leak in xmlschemas.c in xmlSchemaClearValidCtxt(). The vctxt->idcKeys and associated counters are not cleaned up in xmlSchemaClearValidCtxt() as they are in xmlSchemaFreeValidCtxt(). As a result, vctxt->idcKeys grows with each xmlValidateDoc() call that uses the same context and that memory is never freed. Similarly, vctxt->nbIdcKeys and vctxt->sizeIdcKeys increment and are never reset.
You can reproduce this issue with something like:
for (i = 0; i < 100000; i++) xmlSchemaValidateDoc(vctxt, xml_doc);
Top will show the process resident memory usage growing. If the test is long enough, all memory will be consumed. This is the behavior with my schemas and xml files.
A proposed patch is attached. This fixes the issue for me on 2.9.7.