mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-30 22:43:14 +03:00
more memory related code cleanups. Daniel
* HTMLparser.c parser.c relaxng.c xmlschemas.c: more memory related code cleanups. Daniel
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
Thu Sep 23 01:04:30 CEST 2004 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* parser.c: fixed a bunch of errors when realloc failed.
|
* parser.c: fixed a bunch of errors when realloc failed.
|
||||||
|
15
HTMLparser.c
15
HTMLparser.c
@ -1703,12 +1703,15 @@ static const htmlEntityDesc html40EntitiesTable[] = {
|
|||||||
* Macro used to grow the current buffer.
|
* Macro used to grow the current buffer.
|
||||||
*/
|
*/
|
||||||
#define growBuffer(buffer) { \
|
#define growBuffer(buffer) { \
|
||||||
|
xmlChar *tmp; \
|
||||||
buffer##_size *= 2; \
|
buffer##_size *= 2; \
|
||||||
buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \
|
tmp = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \
|
||||||
if (buffer == NULL) { \
|
if (tmp == NULL) { \
|
||||||
htmlErrMemory(ctxt, "growing buffer\n"); \
|
htmlErrMemory(ctxt, "growing buffer\n"); \
|
||||||
|
xmlFree(buffer); \
|
||||||
return(NULL); \
|
return(NULL); \
|
||||||
} \
|
} \
|
||||||
|
buffer = tmp; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2849,13 +2852,17 @@ htmlParseComment(htmlParserCtxtPtr ctxt) {
|
|||||||
((cur != '>') ||
|
((cur != '>') ||
|
||||||
(r != '-') || (q != '-'))) {
|
(r != '-') || (q != '-'))) {
|
||||||
if (len + 5 >= size) {
|
if (len + 5 >= size) {
|
||||||
|
xmlChar *tmp;
|
||||||
|
|
||||||
size *= 2;
|
size *= 2;
|
||||||
buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
|
tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
|
||||||
if (buf == NULL) {
|
if (tmp == NULL) {
|
||||||
|
xmlFree(buf);
|
||||||
htmlErrMemory(ctxt, "growing buffer failed\n");
|
htmlErrMemory(ctxt, "growing buffer failed\n");
|
||||||
ctxt->instate = state;
|
ctxt->instate = state;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
buf = tmp;
|
||||||
}
|
}
|
||||||
COPY_BUF(ql,buf,len,q);
|
COPY_BUF(ql,buf,len,q);
|
||||||
q = r;
|
q = r;
|
||||||
|
15
parser.c
15
parser.c
@ -645,8 +645,8 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* plit the element name into prefix:localname , the string found
|
* split the element name into prefix:localname , the string found
|
||||||
* are within the DTD and hen not associated to namespace names.
|
* are within the DTD and then not associated to namespace names.
|
||||||
*/
|
*/
|
||||||
name = xmlSplitQName3(fullname, &len);
|
name = xmlSplitQName3(fullname, &len);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
@ -663,17 +663,20 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt,
|
|||||||
defaults = xmlHashLookup2(ctxt->attsDefault, name, prefix);
|
defaults = xmlHashLookup2(ctxt->attsDefault, name, prefix);
|
||||||
if (defaults == NULL) {
|
if (defaults == NULL) {
|
||||||
defaults = (xmlDefAttrsPtr) xmlMalloc(sizeof(xmlDefAttrs) +
|
defaults = (xmlDefAttrsPtr) xmlMalloc(sizeof(xmlDefAttrs) +
|
||||||
12 * sizeof(const xmlChar *));
|
(4 * 4) * sizeof(const xmlChar *));
|
||||||
if (defaults == NULL)
|
if (defaults == NULL)
|
||||||
goto mem_error;
|
goto mem_error;
|
||||||
defaults->maxAttrs = 4;
|
|
||||||
defaults->nbAttrs = 0;
|
defaults->nbAttrs = 0;
|
||||||
|
defaults->maxAttrs = 4;
|
||||||
xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix, defaults, NULL);
|
xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix, defaults, NULL);
|
||||||
} else if (defaults->nbAttrs >= defaults->maxAttrs) {
|
} 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 *));
|
(2 * defaults->maxAttrs * 4) * sizeof(const xmlChar *));
|
||||||
if (defaults == NULL)
|
if (temp == NULL)
|
||||||
goto mem_error;
|
goto mem_error;
|
||||||
|
defaults = temp;
|
||||||
defaults->maxAttrs *= 2;
|
defaults->maxAttrs *= 2;
|
||||||
xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix, defaults, NULL);
|
xmlHashUpdateEntry2(ctxt->attsDefault, name, prefix, defaults, NULL);
|
||||||
}
|
}
|
||||||
|
@ -3964,14 +3964,17 @@ xmlRelaxNGGetElements(xmlRelaxNGParserCtxtPtr ctxt,
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
} else if (max <= len) {
|
} else if (max <= len) {
|
||||||
|
xmlRelaxNGDefinePtr *temp;
|
||||||
|
|
||||||
max *= 2;
|
max *= 2;
|
||||||
ret =
|
temp = xmlRealloc(ret,
|
||||||
xmlRealloc(ret,
|
|
||||||
(max + 1) * sizeof(xmlRelaxNGDefinePtr));
|
(max + 1) * sizeof(xmlRelaxNGDefinePtr));
|
||||||
if (ret == NULL) {
|
if (temp == NULL) {
|
||||||
xmlRngPErrMemory(ctxt, "getting element list\n");
|
xmlRngPErrMemory(ctxt, "getting element list\n");
|
||||||
|
xmlFree(ret);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
ret = temp;
|
||||||
}
|
}
|
||||||
ret[len++] = cur;
|
ret[len++] = cur;
|
||||||
ret[len] = NULL;
|
ret[len] = NULL;
|
||||||
|
@ -13103,6 +13103,7 @@ xmlSchemaRegisterAttributes(xmlSchemaValidCtxtPtr ctxt, xmlAttrPtr attrs)
|
|||||||
xmlSchemaVErrMemory(ctxt, "registering attributes", NULL);
|
xmlSchemaVErrMemory(ctxt, "registering attributes", NULL);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
memset(tmp, 0, sizeof(xmlSchemaAttrState));
|
||||||
tmp->attr = attrs;
|
tmp->attr = attrs;
|
||||||
tmp->state = XML_SCHEMAS_ATTR_UNKNOWN;
|
tmp->state = XML_SCHEMAS_ATTR_UNKNOWN;
|
||||||
tmp->next = NULL;
|
tmp->next = NULL;
|
||||||
|
Reference in New Issue
Block a user