malloc-fail: Handle malloc failures in xmlSchemaInitTypes

Note that this changes the return value of public function
xmlSchemaInitTypes from void to int. This shouldn't break the ABI on
most platforms.

Found when investigating #500.
This commit is contained in:
Nick Wellnhofer 2023-03-14 13:55:06 +01:00
parent 64b76f8163
commit f8efa589e8
3 changed files with 163 additions and 46 deletions

View File

@ -30,7 +30,7 @@ typedef enum {
XML_SCHEMA_WHITESPACE_COLLAPSE = 3 XML_SCHEMA_WHITESPACE_COLLAPSE = 3
} xmlSchemaWhitespaceValueType; } xmlSchemaWhitespaceValueType;
XMLPUBFUN void XMLPUBFUN int
xmlSchemaInitTypes (void); xmlSchemaInitTypes (void);
XML_DEPRECATED XML_DEPRECATED
XMLPUBFUN void XMLPUBFUN void

View File

@ -21457,7 +21457,8 @@ xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
* the API; i.e. not automatically by the validated instance document. * the API; i.e. not automatically by the validated instance document.
*/ */
xmlSchemaInitTypes(); if (xmlSchemaInitTypes() < 0)
return (NULL);
if (ctxt == NULL) if (ctxt == NULL)
return (NULL); return (NULL);

View File

@ -385,18 +385,61 @@ xmlSchemaAddParticle(void)
return (ret); return (ret);
} }
static void
xmlSchemaFreeTypeEntry(void *type, const xmlChar *name ATTRIBUTE_UNUSED) {
xmlSchemaFreeType((xmlSchemaTypePtr) type);
}
/**
* xmlSchemaCleanupTypesInternal:
*
* Cleanup the default XML Schemas type library
*/
static void
xmlSchemaCleanupTypesInternal(void) {
xmlSchemaParticlePtr particle;
/*
* Free xs:anyType.
*/
if (xmlSchemaTypeAnyTypeDef != NULL) {
/* Attribute wildcard. */
xmlSchemaFreeWildcard(xmlSchemaTypeAnyTypeDef->attributeWildcard);
/* Content type. */
particle = (xmlSchemaParticlePtr) xmlSchemaTypeAnyTypeDef->subtypes;
/* Wildcard. */
xmlSchemaFreeWildcard((xmlSchemaWildcardPtr)
particle->children->children->children);
xmlFree((xmlSchemaParticlePtr) particle->children->children);
/* Sequence model group. */
xmlFree((xmlSchemaModelGroupPtr) particle->children);
xmlFree((xmlSchemaParticlePtr) particle);
xmlSchemaTypeAnyTypeDef->subtypes = NULL;
xmlSchemaTypeAnyTypeDef = NULL;
}
xmlHashFree(xmlSchemaTypesBank, xmlSchemaFreeTypeEntry);
xmlSchemaTypesBank = NULL;
/* Note that the xmlSchemaType*Def pointers aren't set to NULL. */
}
/* /*
* xmlSchemaInitTypes: * xmlSchemaInitTypes:
* *
* Initialize the default XML Schemas type library * Initialize the default XML Schemas type library
*
* Returns 0 on success, -1 on error.
*/ */
void int
xmlSchemaInitTypes(void) xmlSchemaInitTypes(void)
{ {
if (xmlSchemaTypesInitialized != 0) if (xmlSchemaTypesInitialized != 0)
return; return (0);
xmlSchemaTypesBank = xmlHashCreate(40); xmlSchemaTypesBank = xmlHashCreate(40);
if (xmlSchemaTypesBank == NULL) {
xmlSchemaTypeErrMemory(NULL, NULL);
goto error;
}
/* /*
* 3.4.7 Built-in Complex Type Definition * 3.4.7 Built-in Complex Type Definition
@ -404,10 +447,8 @@ xmlSchemaInitTypes(void)
xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType", xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType",
XML_SCHEMAS_ANYTYPE, XML_SCHEMAS_ANYTYPE,
NULL); NULL);
if (xmlSchemaTypeAnyTypeDef == NULL) { if (xmlSchemaTypeAnyTypeDef == NULL)
xmlSchemaTypeErrMemory(NULL, NULL); goto error;
return;
}
xmlSchemaTypeAnyTypeDef->baseType = xmlSchemaTypeAnyTypeDef; xmlSchemaTypeAnyTypeDef->baseType = xmlSchemaTypeAnyTypeDef;
xmlSchemaTypeAnyTypeDef->contentType = XML_SCHEMA_CONTENT_MIXED; xmlSchemaTypeAnyTypeDef->contentType = XML_SCHEMA_CONTENT_MIXED;
/* /*
@ -421,14 +462,14 @@ xmlSchemaInitTypes(void)
/* First particle. */ /* First particle. */
particle = xmlSchemaAddParticle(); particle = xmlSchemaAddParticle();
if (particle == NULL) if (particle == NULL)
return; goto error;
xmlSchemaTypeAnyTypeDef->subtypes = (xmlSchemaTypePtr) particle; xmlSchemaTypeAnyTypeDef->subtypes = (xmlSchemaTypePtr) particle;
/* Sequence model group. */ /* Sequence model group. */
sequence = (xmlSchemaModelGroupPtr) sequence = (xmlSchemaModelGroupPtr)
xmlMalloc(sizeof(xmlSchemaModelGroup)); xmlMalloc(sizeof(xmlSchemaModelGroup));
if (sequence == NULL) { if (sequence == NULL) {
xmlSchemaTypeErrMemory(NULL, "allocating model group component"); xmlSchemaTypeErrMemory(NULL, "allocating model group component");
return; goto error;
} }
memset(sequence, 0, sizeof(xmlSchemaModelGroup)); memset(sequence, 0, sizeof(xmlSchemaModelGroup));
sequence->type = XML_SCHEMA_TYPE_SEQUENCE; sequence->type = XML_SCHEMA_TYPE_SEQUENCE;
@ -436,7 +477,7 @@ xmlSchemaInitTypes(void)
/* Second particle. */ /* Second particle. */
particle = xmlSchemaAddParticle(); particle = xmlSchemaAddParticle();
if (particle == NULL) if (particle == NULL)
return; goto error;
particle->minOccurs = 0; particle->minOccurs = 0;
particle->maxOccurs = UNBOUNDED; particle->maxOccurs = UNBOUNDED;
sequence->children = (xmlSchemaTreeItemPtr) particle; sequence->children = (xmlSchemaTreeItemPtr) particle;
@ -444,7 +485,7 @@ xmlSchemaInitTypes(void)
wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard)); wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));
if (wild == NULL) { if (wild == NULL) {
xmlSchemaTypeErrMemory(NULL, "allocating wildcard component"); xmlSchemaTypeErrMemory(NULL, "allocating wildcard component");
return; goto error;
} }
memset(wild, 0, sizeof(xmlSchemaWildcard)); memset(wild, 0, sizeof(xmlSchemaWildcard));
wild->type = XML_SCHEMA_TYPE_ANY; wild->type = XML_SCHEMA_TYPE_ANY;
@ -458,7 +499,7 @@ xmlSchemaInitTypes(void)
if (wild == NULL) { if (wild == NULL) {
xmlSchemaTypeErrMemory(NULL, "could not create an attribute " xmlSchemaTypeErrMemory(NULL, "could not create an attribute "
"wildcard on anyType"); "wildcard on anyType");
return; goto error;
} }
memset(wild, 0, sizeof(xmlSchemaWildcard)); memset(wild, 0, sizeof(xmlSchemaWildcard));
wild->any = 1; wild->any = 1;
@ -468,66 +509,106 @@ xmlSchemaInitTypes(void)
xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType", xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType",
XML_SCHEMAS_ANYSIMPLETYPE, XML_SCHEMAS_ANYSIMPLETYPE,
xmlSchemaTypeAnyTypeDef); xmlSchemaTypeAnyTypeDef);
if (xmlSchemaTypeAnySimpleTypeDef == NULL)
goto error;
/* /*
* primitive datatypes * primitive datatypes
*/ */
xmlSchemaTypeStringDef = xmlSchemaInitBasicType("string", xmlSchemaTypeStringDef = xmlSchemaInitBasicType("string",
XML_SCHEMAS_STRING, XML_SCHEMAS_STRING,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeStringDef == NULL)
goto error;
xmlSchemaTypeDecimalDef = xmlSchemaInitBasicType("decimal", xmlSchemaTypeDecimalDef = xmlSchemaInitBasicType("decimal",
XML_SCHEMAS_DECIMAL, XML_SCHEMAS_DECIMAL,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDecimalDef == NULL)
goto error;
xmlSchemaTypeDateDef = xmlSchemaInitBasicType("date", xmlSchemaTypeDateDef = xmlSchemaInitBasicType("date",
XML_SCHEMAS_DATE, XML_SCHEMAS_DATE,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDateDef == NULL)
goto error;
xmlSchemaTypeDatetimeDef = xmlSchemaInitBasicType("dateTime", xmlSchemaTypeDatetimeDef = xmlSchemaInitBasicType("dateTime",
XML_SCHEMAS_DATETIME, XML_SCHEMAS_DATETIME,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDatetimeDef == NULL)
goto error;
xmlSchemaTypeTimeDef = xmlSchemaInitBasicType("time", xmlSchemaTypeTimeDef = xmlSchemaInitBasicType("time",
XML_SCHEMAS_TIME, XML_SCHEMAS_TIME,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeTimeDef == NULL)
goto error;
xmlSchemaTypeGYearDef = xmlSchemaInitBasicType("gYear", xmlSchemaTypeGYearDef = xmlSchemaInitBasicType("gYear",
XML_SCHEMAS_GYEAR, XML_SCHEMAS_GYEAR,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGYearDef == NULL)
goto error;
xmlSchemaTypeGYearMonthDef = xmlSchemaInitBasicType("gYearMonth", xmlSchemaTypeGYearMonthDef = xmlSchemaInitBasicType("gYearMonth",
XML_SCHEMAS_GYEARMONTH, XML_SCHEMAS_GYEARMONTH,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGYearMonthDef == NULL)
goto error;
xmlSchemaTypeGMonthDef = xmlSchemaInitBasicType("gMonth", xmlSchemaTypeGMonthDef = xmlSchemaInitBasicType("gMonth",
XML_SCHEMAS_GMONTH, XML_SCHEMAS_GMONTH,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGMonthDef == NULL)
goto error;
xmlSchemaTypeGMonthDayDef = xmlSchemaInitBasicType("gMonthDay", xmlSchemaTypeGMonthDayDef = xmlSchemaInitBasicType("gMonthDay",
XML_SCHEMAS_GMONTHDAY, XML_SCHEMAS_GMONTHDAY,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGMonthDayDef == NULL)
goto error;
xmlSchemaTypeGDayDef = xmlSchemaInitBasicType("gDay", xmlSchemaTypeGDayDef = xmlSchemaInitBasicType("gDay",
XML_SCHEMAS_GDAY, XML_SCHEMAS_GDAY,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeGDayDef == NULL)
goto error;
xmlSchemaTypeDurationDef = xmlSchemaInitBasicType("duration", xmlSchemaTypeDurationDef = xmlSchemaInitBasicType("duration",
XML_SCHEMAS_DURATION, XML_SCHEMAS_DURATION,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDurationDef == NULL)
goto error;
xmlSchemaTypeFloatDef = xmlSchemaInitBasicType("float", xmlSchemaTypeFloatDef = xmlSchemaInitBasicType("float",
XML_SCHEMAS_FLOAT, XML_SCHEMAS_FLOAT,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeFloatDef == NULL)
goto error;
xmlSchemaTypeDoubleDef = xmlSchemaInitBasicType("double", xmlSchemaTypeDoubleDef = xmlSchemaInitBasicType("double",
XML_SCHEMAS_DOUBLE, XML_SCHEMAS_DOUBLE,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeDoubleDef == NULL)
goto error;
xmlSchemaTypeBooleanDef = xmlSchemaInitBasicType("boolean", xmlSchemaTypeBooleanDef = xmlSchemaInitBasicType("boolean",
XML_SCHEMAS_BOOLEAN, XML_SCHEMAS_BOOLEAN,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeBooleanDef == NULL)
goto error;
xmlSchemaTypeAnyURIDef = xmlSchemaInitBasicType("anyURI", xmlSchemaTypeAnyURIDef = xmlSchemaInitBasicType("anyURI",
XML_SCHEMAS_ANYURI, XML_SCHEMAS_ANYURI,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeAnyURIDef == NULL)
goto error;
xmlSchemaTypeHexBinaryDef = xmlSchemaInitBasicType("hexBinary", xmlSchemaTypeHexBinaryDef = xmlSchemaInitBasicType("hexBinary",
XML_SCHEMAS_HEXBINARY, XML_SCHEMAS_HEXBINARY,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeHexBinaryDef == NULL)
goto error;
xmlSchemaTypeBase64BinaryDef xmlSchemaTypeBase64BinaryDef
= xmlSchemaInitBasicType("base64Binary", XML_SCHEMAS_BASE64BINARY, = xmlSchemaInitBasicType("base64Binary", XML_SCHEMAS_BASE64BINARY,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeBase64BinaryDef == NULL)
goto error;
xmlSchemaTypeNotationDef = xmlSchemaInitBasicType("NOTATION", xmlSchemaTypeNotationDef = xmlSchemaInitBasicType("NOTATION",
XML_SCHEMAS_NOTATION, XML_SCHEMAS_NOTATION,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeNotationDef == NULL)
goto error;
xmlSchemaTypeQNameDef = xmlSchemaInitBasicType("QName", xmlSchemaTypeQNameDef = xmlSchemaInitBasicType("QName",
XML_SCHEMAS_QNAME, XML_SCHEMAS_QNAME,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeQNameDef == NULL)
goto error;
/* /*
* derived datatypes * derived datatypes
@ -535,69 +616,113 @@ xmlSchemaInitTypes(void)
xmlSchemaTypeIntegerDef = xmlSchemaInitBasicType("integer", xmlSchemaTypeIntegerDef = xmlSchemaInitBasicType("integer",
XML_SCHEMAS_INTEGER, XML_SCHEMAS_INTEGER,
xmlSchemaTypeDecimalDef); xmlSchemaTypeDecimalDef);
if (xmlSchemaTypeIntegerDef == NULL)
goto error;
xmlSchemaTypeNonPositiveIntegerDef = xmlSchemaTypeNonPositiveIntegerDef =
xmlSchemaInitBasicType("nonPositiveInteger", xmlSchemaInitBasicType("nonPositiveInteger",
XML_SCHEMAS_NPINTEGER, XML_SCHEMAS_NPINTEGER,
xmlSchemaTypeIntegerDef); xmlSchemaTypeIntegerDef);
if (xmlSchemaTypeNonPositiveIntegerDef == NULL)
goto error;
xmlSchemaTypeNegativeIntegerDef = xmlSchemaTypeNegativeIntegerDef =
xmlSchemaInitBasicType("negativeInteger", XML_SCHEMAS_NINTEGER, xmlSchemaInitBasicType("negativeInteger", XML_SCHEMAS_NINTEGER,
xmlSchemaTypeNonPositiveIntegerDef); xmlSchemaTypeNonPositiveIntegerDef);
if (xmlSchemaTypeNegativeIntegerDef == NULL)
goto error;
xmlSchemaTypeLongDef = xmlSchemaTypeLongDef =
xmlSchemaInitBasicType("long", XML_SCHEMAS_LONG, xmlSchemaInitBasicType("long", XML_SCHEMAS_LONG,
xmlSchemaTypeIntegerDef); xmlSchemaTypeIntegerDef);
if (xmlSchemaTypeLongDef == NULL)
goto error;
xmlSchemaTypeIntDef = xmlSchemaInitBasicType("int", XML_SCHEMAS_INT, xmlSchemaTypeIntDef = xmlSchemaInitBasicType("int", XML_SCHEMAS_INT,
xmlSchemaTypeLongDef); xmlSchemaTypeLongDef);
if (xmlSchemaTypeIntDef == NULL)
goto error;
xmlSchemaTypeShortDef = xmlSchemaInitBasicType("short", xmlSchemaTypeShortDef = xmlSchemaInitBasicType("short",
XML_SCHEMAS_SHORT, XML_SCHEMAS_SHORT,
xmlSchemaTypeIntDef); xmlSchemaTypeIntDef);
if (xmlSchemaTypeShortDef == NULL)
goto error;
xmlSchemaTypeByteDef = xmlSchemaInitBasicType("byte", xmlSchemaTypeByteDef = xmlSchemaInitBasicType("byte",
XML_SCHEMAS_BYTE, XML_SCHEMAS_BYTE,
xmlSchemaTypeShortDef); xmlSchemaTypeShortDef);
if (xmlSchemaTypeByteDef == NULL)
goto error;
xmlSchemaTypeNonNegativeIntegerDef = xmlSchemaTypeNonNegativeIntegerDef =
xmlSchemaInitBasicType("nonNegativeInteger", xmlSchemaInitBasicType("nonNegativeInteger",
XML_SCHEMAS_NNINTEGER, XML_SCHEMAS_NNINTEGER,
xmlSchemaTypeIntegerDef); xmlSchemaTypeIntegerDef);
if (xmlSchemaTypeNonNegativeIntegerDef == NULL)
goto error;
xmlSchemaTypeUnsignedLongDef = xmlSchemaTypeUnsignedLongDef =
xmlSchemaInitBasicType("unsignedLong", XML_SCHEMAS_ULONG, xmlSchemaInitBasicType("unsignedLong", XML_SCHEMAS_ULONG,
xmlSchemaTypeNonNegativeIntegerDef); xmlSchemaTypeNonNegativeIntegerDef);
if (xmlSchemaTypeUnsignedLongDef == NULL)
goto error;
xmlSchemaTypeUnsignedIntDef = xmlSchemaTypeUnsignedIntDef =
xmlSchemaInitBasicType("unsignedInt", XML_SCHEMAS_UINT, xmlSchemaInitBasicType("unsignedInt", XML_SCHEMAS_UINT,
xmlSchemaTypeUnsignedLongDef); xmlSchemaTypeUnsignedLongDef);
if (xmlSchemaTypeUnsignedIntDef == NULL)
goto error;
xmlSchemaTypeUnsignedShortDef = xmlSchemaTypeUnsignedShortDef =
xmlSchemaInitBasicType("unsignedShort", XML_SCHEMAS_USHORT, xmlSchemaInitBasicType("unsignedShort", XML_SCHEMAS_USHORT,
xmlSchemaTypeUnsignedIntDef); xmlSchemaTypeUnsignedIntDef);
if (xmlSchemaTypeUnsignedShortDef == NULL)
goto error;
xmlSchemaTypeUnsignedByteDef = xmlSchemaTypeUnsignedByteDef =
xmlSchemaInitBasicType("unsignedByte", XML_SCHEMAS_UBYTE, xmlSchemaInitBasicType("unsignedByte", XML_SCHEMAS_UBYTE,
xmlSchemaTypeUnsignedShortDef); xmlSchemaTypeUnsignedShortDef);
if (xmlSchemaTypeUnsignedByteDef == NULL)
goto error;
xmlSchemaTypePositiveIntegerDef = xmlSchemaTypePositiveIntegerDef =
xmlSchemaInitBasicType("positiveInteger", XML_SCHEMAS_PINTEGER, xmlSchemaInitBasicType("positiveInteger", XML_SCHEMAS_PINTEGER,
xmlSchemaTypeNonNegativeIntegerDef); xmlSchemaTypeNonNegativeIntegerDef);
if (xmlSchemaTypePositiveIntegerDef == NULL)
goto error;
xmlSchemaTypeNormStringDef = xmlSchemaInitBasicType("normalizedString", xmlSchemaTypeNormStringDef = xmlSchemaInitBasicType("normalizedString",
XML_SCHEMAS_NORMSTRING, XML_SCHEMAS_NORMSTRING,
xmlSchemaTypeStringDef); xmlSchemaTypeStringDef);
if (xmlSchemaTypeNormStringDef == NULL)
goto error;
xmlSchemaTypeTokenDef = xmlSchemaInitBasicType("token", xmlSchemaTypeTokenDef = xmlSchemaInitBasicType("token",
XML_SCHEMAS_TOKEN, XML_SCHEMAS_TOKEN,
xmlSchemaTypeNormStringDef); xmlSchemaTypeNormStringDef);
if (xmlSchemaTypeTokenDef == NULL)
goto error;
xmlSchemaTypeLanguageDef = xmlSchemaInitBasicType("language", xmlSchemaTypeLanguageDef = xmlSchemaInitBasicType("language",
XML_SCHEMAS_LANGUAGE, XML_SCHEMAS_LANGUAGE,
xmlSchemaTypeTokenDef); xmlSchemaTypeTokenDef);
if (xmlSchemaTypeLanguageDef == NULL)
goto error;
xmlSchemaTypeNameDef = xmlSchemaInitBasicType("Name", xmlSchemaTypeNameDef = xmlSchemaInitBasicType("Name",
XML_SCHEMAS_NAME, XML_SCHEMAS_NAME,
xmlSchemaTypeTokenDef); xmlSchemaTypeTokenDef);
if (xmlSchemaTypeNameDef == NULL)
goto error;
xmlSchemaTypeNmtokenDef = xmlSchemaInitBasicType("NMTOKEN", xmlSchemaTypeNmtokenDef = xmlSchemaInitBasicType("NMTOKEN",
XML_SCHEMAS_NMTOKEN, XML_SCHEMAS_NMTOKEN,
xmlSchemaTypeTokenDef); xmlSchemaTypeTokenDef);
if (xmlSchemaTypeNmtokenDef == NULL)
goto error;
xmlSchemaTypeNCNameDef = xmlSchemaInitBasicType("NCName", xmlSchemaTypeNCNameDef = xmlSchemaInitBasicType("NCName",
XML_SCHEMAS_NCNAME, XML_SCHEMAS_NCNAME,
xmlSchemaTypeNameDef); xmlSchemaTypeNameDef);
if (xmlSchemaTypeNCNameDef == NULL)
goto error;
xmlSchemaTypeIdDef = xmlSchemaInitBasicType("ID", XML_SCHEMAS_ID, xmlSchemaTypeIdDef = xmlSchemaInitBasicType("ID", XML_SCHEMAS_ID,
xmlSchemaTypeNCNameDef); xmlSchemaTypeNCNameDef);
if (xmlSchemaTypeIdDef == NULL)
goto error;
xmlSchemaTypeIdrefDef = xmlSchemaInitBasicType("IDREF", xmlSchemaTypeIdrefDef = xmlSchemaInitBasicType("IDREF",
XML_SCHEMAS_IDREF, XML_SCHEMAS_IDREF,
xmlSchemaTypeNCNameDef); xmlSchemaTypeNCNameDef);
if (xmlSchemaTypeIdrefDef == NULL)
goto error;
xmlSchemaTypeEntityDef = xmlSchemaInitBasicType("ENTITY", xmlSchemaTypeEntityDef = xmlSchemaInitBasicType("ENTITY",
XML_SCHEMAS_ENTITY, XML_SCHEMAS_ENTITY,
xmlSchemaTypeNCNameDef); xmlSchemaTypeNCNameDef);
if (xmlSchemaTypeEntityDef == NULL)
goto error;
/* /*
* Derived list types. * Derived list types.
*/ */
@ -605,25 +730,31 @@ xmlSchemaInitTypes(void)
xmlSchemaTypeEntitiesDef = xmlSchemaInitBasicType("ENTITIES", xmlSchemaTypeEntitiesDef = xmlSchemaInitBasicType("ENTITIES",
XML_SCHEMAS_ENTITIES, XML_SCHEMAS_ENTITIES,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeEntitiesDef == NULL)
goto error;
xmlSchemaTypeEntitiesDef->subtypes = xmlSchemaTypeEntityDef; xmlSchemaTypeEntitiesDef->subtypes = xmlSchemaTypeEntityDef;
/* IDREFS */ /* IDREFS */
xmlSchemaTypeIdrefsDef = xmlSchemaInitBasicType("IDREFS", xmlSchemaTypeIdrefsDef = xmlSchemaInitBasicType("IDREFS",
XML_SCHEMAS_IDREFS, XML_SCHEMAS_IDREFS,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeIdrefsDef == NULL)
goto error;
xmlSchemaTypeIdrefsDef->subtypes = xmlSchemaTypeIdrefDef; xmlSchemaTypeIdrefsDef->subtypes = xmlSchemaTypeIdrefDef;
/* NMTOKENS */ /* NMTOKENS */
xmlSchemaTypeNmtokensDef = xmlSchemaInitBasicType("NMTOKENS", xmlSchemaTypeNmtokensDef = xmlSchemaInitBasicType("NMTOKENS",
XML_SCHEMAS_NMTOKENS, XML_SCHEMAS_NMTOKENS,
xmlSchemaTypeAnySimpleTypeDef); xmlSchemaTypeAnySimpleTypeDef);
if (xmlSchemaTypeNmtokensDef == NULL)
goto error;
xmlSchemaTypeNmtokensDef->subtypes = xmlSchemaTypeNmtokenDef; xmlSchemaTypeNmtokensDef->subtypes = xmlSchemaTypeNmtokenDef;
xmlSchemaTypesInitialized = 1; xmlSchemaTypesInitialized = 1;
} return (0);
static void error:
xmlSchemaFreeTypeEntry(void *type, const xmlChar *name ATTRIBUTE_UNUSED) { xmlSchemaCleanupTypesInternal();
xmlSchemaFreeType((xmlSchemaTypePtr) type); return (-1);
} }
/** /**
@ -632,34 +763,16 @@ xmlSchemaFreeTypeEntry(void *type, const xmlChar *name ATTRIBUTE_UNUSED) {
* DEPRECATED: This function will be made private. Call xmlCleanupParser * DEPRECATED: This function will be made private. Call xmlCleanupParser
* to free global state but see the warnings there. xmlCleanupParser * to free global state but see the warnings there. xmlCleanupParser
* should be only called once at program exit. In most cases, you don't * should be only called once at program exit. In most cases, you don't
* have call cleanup functions at all. * have to call cleanup functions at all.
* *
* Cleanup the default XML Schemas type library * Cleanup the default XML Schemas type library
*/ */
void void
xmlSchemaCleanupTypes(void) { xmlSchemaCleanupTypes(void) {
if (xmlSchemaTypesInitialized == 0) if (xmlSchemaTypesInitialized != 0) {
return; xmlSchemaCleanupTypesInternal();
/* xmlSchemaTypesInitialized = 0;
* Free xs:anyType.
*/
{
xmlSchemaParticlePtr particle;
/* Attribute wildcard. */
xmlSchemaFreeWildcard(xmlSchemaTypeAnyTypeDef->attributeWildcard);
/* Content type. */
particle = (xmlSchemaParticlePtr) xmlSchemaTypeAnyTypeDef->subtypes;
/* Wildcard. */
xmlSchemaFreeWildcard((xmlSchemaWildcardPtr)
particle->children->children->children);
xmlFree((xmlSchemaParticlePtr) particle->children->children);
/* Sequence model group. */
xmlFree((xmlSchemaModelGroupPtr) particle->children);
xmlFree((xmlSchemaParticlePtr) particle);
xmlSchemaTypeAnyTypeDef->subtypes = NULL;
} }
xmlHashFree(xmlSchemaTypesBank, xmlSchemaFreeTypeEntry);
xmlSchemaTypesInitialized = 0;
} }
/** /**
@ -754,8 +867,9 @@ xmlSchemaIsBuiltInTypeFacet(xmlSchemaTypePtr type, int facetType)
xmlSchemaTypePtr xmlSchemaTypePtr
xmlSchemaGetBuiltInType(xmlSchemaValType type) xmlSchemaGetBuiltInType(xmlSchemaValType type)
{ {
if (xmlSchemaTypesInitialized == 0) if ((xmlSchemaTypesInitialized == 0) &&
xmlSchemaInitTypes(); (xmlSchemaInitTypes() < 0))
return (NULL);
switch (type) { switch (type) {
case XML_SCHEMAS_ANYSIMPLETYPE: case XML_SCHEMAS_ANYSIMPLETYPE:
@ -1087,8 +1201,9 @@ xmlSchemaFreeValue(xmlSchemaValPtr value) {
*/ */
xmlSchemaTypePtr xmlSchemaTypePtr
xmlSchemaGetPredefinedType(const xmlChar *name, const xmlChar *ns) { xmlSchemaGetPredefinedType(const xmlChar *name, const xmlChar *ns) {
if (xmlSchemaTypesInitialized == 0) if ((xmlSchemaTypesInitialized == 0) &&
xmlSchemaInitTypes(); (xmlSchemaInitTypes() < 0))
return (NULL);
if (name == NULL) if (name == NULL)
return(NULL); return(NULL);
return((xmlSchemaTypePtr) xmlHashLookup2(xmlSchemaTypesBank, name, ns)); return((xmlSchemaTypePtr) xmlHashLookup2(xmlSchemaTypesBank, name, ns));
@ -2257,8 +2372,9 @@ xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value,
xmlChar *norm = NULL; xmlChar *norm = NULL;
int ret = 0; int ret = 0;
if (xmlSchemaTypesInitialized == 0) if ((xmlSchemaTypesInitialized == 0) &&
xmlSchemaInitTypes(); (xmlSchemaInitTypes() < 0))
return (-1);
if (type == NULL) if (type == NULL)
return (-1); return (-1);