Commit 079f6a75 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

more memory related code cleanups. Daniel

* HTMLparser.c parser.c relaxng.c xmlschemas.c: more memory related
  code cleanups.
Daniel
parent 2248ff17
Thu Sep 23 15:14:12 CEST 2004 Daniel Veillard <daniel@veillard.com>
* HTMLparser.c parser.c relaxng.c xmlschemas.c: more memory related
code cleanups.
Thu Sep 23 01:04:30 CEST 2004 Daniel Veillard <daniel@veillard.com>
* parser.c: fixed a bunch of errors when realloc failed.
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment