diff --git a/ChangeLog b/ChangeLog index dd083282..78bcb048 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Sep 23 15:14:12 CEST 2004 Daniel Veillard + + * HTMLparser.c parser.c relaxng.c xmlschemas.c: more memory related + code cleanups. + Thu Sep 23 01:04:30 CEST 2004 Daniel Veillard * parser.c: fixed a bunch of errors when realloc failed. diff --git a/HTMLparser.c b/HTMLparser.c index 5a033338..10f85166 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -1703,12 +1703,15 @@ static const htmlEntityDesc html40EntitiesTable[] = { * Macro used to grow the current buffer. */ #define growBuffer(buffer) { \ + xmlChar *tmp; \ buffer##_size *= 2; \ - buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ - if (buffer == NULL) { \ + tmp = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ + if (tmp == NULL) { \ htmlErrMemory(ctxt, "growing buffer\n"); \ + xmlFree(buffer); \ return(NULL); \ } \ + buffer = tmp; \ } /** @@ -2849,13 +2852,17 @@ htmlParseComment(htmlParserCtxtPtr ctxt) { ((cur != '>') || (r != '-') || (q != '-'))) { if (len + 5 >= size) { + xmlChar *tmp; + size *= 2; - buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); - if (buf == NULL) { + tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); + if (tmp == NULL) { + xmlFree(buf); htmlErrMemory(ctxt, "growing buffer failed\n"); ctxt->instate = state; return; } + buf = tmp; } COPY_BUF(ql,buf,len,q); q = r; diff --git a/parser.c b/parser.c index 5b6b9ae5..998a97ad 100644 --- a/parser.c +++ b/parser.c @@ -645,8 +645,8 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt, } /* - * plit the element name into prefix:localname , the string found - * are within the DTD and hen not associated to namespace names. + * split the element name into prefix:localname , the string found + * are within the DTD and then not associated to namespace names. */ name = xmlSplitQName3(fullname, &len); if (name == NULL) { @@ -663,17 +663,20 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt, defaults = xmlHashLookup2(ctxt->attsDefault, name, prefix); if (defaults == NULL) { defaults = (xmlDefAttrsPtr) xmlMalloc(sizeof(xmlDefAttrs) + - 12 * sizeof(const xmlChar *)); + (4 * 4) * sizeof(const xmlChar *)); if (defaults == NULL) goto mem_error; - defaults->maxAttrs = 4; defaults->nbAttrs = 0; + defaults->maxAttrs = 4; xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix, defaults, NULL); } else if (defaults->nbAttrs >= defaults->maxAttrs) { - defaults = (xmlDefAttrsPtr) xmlRealloc(defaults, sizeof(xmlDefAttrs) + + xmlDefAttrsPtr temp; + + temp = (xmlDefAttrsPtr) xmlRealloc(defaults, sizeof(xmlDefAttrs) + (2 * defaults->maxAttrs * 4) * sizeof(const xmlChar *)); - if (defaults == NULL) + if (temp == NULL) goto mem_error; + defaults = temp; defaults->maxAttrs *= 2; xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix, defaults, NULL); } diff --git a/relaxng.c b/relaxng.c index 29cdb191..8eb81ece 100644 --- a/relaxng.c +++ b/relaxng.c @@ -3964,14 +3964,17 @@ xmlRelaxNGGetElements(xmlRelaxNGParserCtxtPtr ctxt, return (NULL); } } else if (max <= len) { + xmlRelaxNGDefinePtr *temp; + max *= 2; - ret = - xmlRealloc(ret, + temp = xmlRealloc(ret, (max + 1) * sizeof(xmlRelaxNGDefinePtr)); - if (ret == NULL) { + if (temp == NULL) { xmlRngPErrMemory(ctxt, "getting element list\n"); + xmlFree(ret); return (NULL); } + ret = temp; } ret[len++] = cur; ret[len] = NULL; diff --git a/xmlschemas.c b/xmlschemas.c index 000a0ddf..2592dc33 100644 --- a/xmlschemas.c +++ b/xmlschemas.c @@ -13103,6 +13103,7 @@ xmlSchemaRegisterAttributes(xmlSchemaValidCtxtPtr ctxt, xmlAttrPtr attrs) xmlSchemaVErrMemory(ctxt, "registering attributes", NULL); return (-1); } + memset(tmp, 0, sizeof(xmlSchemaAttrState)); tmp->attr = attrs; tmp->state = XML_SCHEMAS_ATTR_UNKNOWN; tmp->next = NULL;