1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-30 22:43:14 +03:00

applied patch from Steve Ball to avoid a double-free. Daniel

* include/libxml/schemasInternals.h xmlschemas.c: applied patch from
  Steve Ball to avoid a double-free.
Daniel
This commit is contained in:
Daniel Veillard
2004-01-24 08:31:30 +00:00
parent 4773df2a58
commit dda22c15d5
3 changed files with 20 additions and 4 deletions

View File

@ -1,3 +1,8 @@
Sat Jan 24 09:30:22 CET 2004 Daniel Veillard <daniel@veillard.com>
* include/libxml/schemasInternals.h xmlschemas.c: applied patch from
Steve Ball to avoid a double-free.
Fri Jan 23 14:03:21 CET 2004 Daniel Veillard <daniel@veillard.com> Fri Jan 23 14:03:21 CET 2004 Daniel Veillard <daniel@veillard.com>
* doc/examples/*: added io1.c an example ox xmlIO usage and io1.res * doc/examples/*: added io1.c an example ox xmlIO usage and io1.res

View File

@ -379,6 +379,7 @@ struct _xmlSchema {
xmlHashTablePtr groupDecl; xmlHashTablePtr groupDecl;
xmlDictPtr dict; xmlDictPtr dict;
void *includes; /* the includes, this is opaque for now */ void *includes; /* the includes, this is opaque for now */
int preserve; /* whether to free the document */
}; };
XMLPUBFUN void XMLCALL xmlSchemaFreeType (xmlSchemaTypePtr type); XMLPUBFUN void XMLCALL xmlSchemaFreeType (xmlSchemaTypePtr type);

View File

@ -85,6 +85,7 @@ struct _xmlSchemaParserCtxt {
const xmlChar *URL; const xmlChar *URL;
xmlDocPtr doc; xmlDocPtr doc;
int preserve; /* Whether the doc should be freed */
const char *buffer; const char *buffer;
int size; int size;
@ -650,7 +651,7 @@ xmlSchemaFree(xmlSchemaPtr schema)
} }
if (schema->annot != NULL) if (schema->annot != NULL)
xmlSchemaFreeAnnot(schema->annot); xmlSchemaFreeAnnot(schema->annot);
if (schema->doc != NULL) if (schema->doc != NULL && !schema->preserve)
xmlFreeDoc(schema->doc); xmlFreeDoc(schema->doc);
xmlDictFree(schema->dict); xmlDictFree(schema->dict);
@ -3840,6 +3841,8 @@ xmlSchemaNewDocParserCtxt(xmlDocPtr doc)
memset(ret, 0, sizeof(xmlSchemaParserCtxt)); memset(ret, 0, sizeof(xmlSchemaParserCtxt));
ret->doc = doc; ret->doc = doc;
ret->dict = xmlDictCreate(); ret->dict = xmlDictCreate();
/* The application has responsibility for the document */
ret->preserve = 1;
return (ret); return (ret);
} }
@ -3855,7 +3858,7 @@ xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt)
{ {
if (ctxt == NULL) if (ctxt == NULL)
return; return;
if (ctxt->doc != NULL) if (ctxt->doc != NULL && !ctxt->preserve)
xmlFreeDoc(ctxt->doc); xmlFreeDoc(ctxt->doc);
xmlDictFree(ctxt->dict); xmlDictFree(ctxt->dict);
xmlFree(ctxt); xmlFree(ctxt);
@ -4862,6 +4865,7 @@ xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
xmlDocPtr doc; xmlDocPtr doc;
xmlNodePtr root; xmlNodePtr root;
int nberrors; int nberrors;
int preserve = 0;
xmlSchemaInitTypes(); xmlSchemaInitTypes();
@ -4900,6 +4904,7 @@ xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
ctxt->URL = xmlDictLookup(ctxt->dict, BAD_CAST "in_memory_buffer", -1); ctxt->URL = xmlDictLookup(ctxt->dict, BAD_CAST "in_memory_buffer", -1);
} else if (ctxt->doc != NULL) { } else if (ctxt->doc != NULL) {
doc = ctxt->doc; doc = ctxt->doc;
preserve = 1;
} else { } else {
xmlSchemaPErr(ctxt, NULL, xmlSchemaPErr(ctxt, NULL,
XML_SCHEMAP_NOTHING_TO_PARSE, XML_SCHEMAP_NOTHING_TO_PARSE,
@ -4916,7 +4921,9 @@ xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
xmlSchemaPErr(ctxt, (xmlNodePtr) doc, xmlSchemaPErr(ctxt, (xmlNodePtr) doc,
XML_SCHEMAP_NOROOT, XML_SCHEMAP_NOROOT,
"schemas has no root", NULL, NULL); "schemas has no root", NULL, NULL);
if (!preserve) {
xmlFreeDoc(doc); xmlFreeDoc(doc);
}
return (NULL); return (NULL);
} }
@ -4930,10 +4937,13 @@ xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
*/ */
ret = xmlSchemaParseSchema(ctxt, root); ret = xmlSchemaParseSchema(ctxt, root);
if (ret == NULL) { if (ret == NULL) {
if (!preserve) {
xmlFreeDoc(doc); xmlFreeDoc(doc);
}
return (NULL); return (NULL);
} }
ret->doc = doc; ret->doc = doc;
ret->preserve = preserve;
/* /*
* Then fix all the references. * Then fix all the references.