[Expat-checkins] expat/lib xmlparse.c,1.33,1.34
fdrake@users.sourceforge.net
fdrake@users.sourceforge.net
Fri May 17 08:10:03 2002
Update of /cvsroot/expat/expat/lib
In directory usw-pr-cvs1:/tmp/cvs-serv7127/lib
Modified Files:
xmlparse.c
Log Message:
Be more careful about failed MALLOC() and REALLOC() calls. This avoids a
number of potential memory leaks.
Index: xmlparse.c
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmlparse.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** xmlparse.c 17 May 2002 03:41:34 -0000 1.33
--- xmlparse.c 17 May 2002 15:09:34 -0000 1.34
***************
*** 1657,1662 ****
return XML_ERROR_NO_MEMORY;
tag->buf = MALLOC(INIT_TAG_BUF_SIZE);
! if (!tag->buf)
return XML_ERROR_NO_MEMORY;
tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE;
}
--- 1657,1664 ----
return XML_ERROR_NO_MEMORY;
tag->buf = MALLOC(INIT_TAG_BUF_SIZE);
! if (!tag->buf) {
! FREE(tag);
return XML_ERROR_NO_MEMORY;
+ }
tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE;
}
***************
*** 2200,2206 ****
b = freeBindingList;
if (len > b->uriAlloc) {
! b->uri = REALLOC(b->uri, sizeof(XML_Char) * (len + EXPAND_SPARE));
! if (!b->uri)
return 0;
b->uriAlloc = len + EXPAND_SPARE;
}
--- 2202,2210 ----
b = freeBindingList;
if (len > b->uriAlloc) {
! XML_Char *temp = REALLOC(b->uri,
! sizeof(XML_Char) * (len + EXPAND_SPARE));
! if (temp == NULL)
return 0;
+ b->uri = temp;
b->uriAlloc = len + EXPAND_SPARE;
}
***************
*** 3142,3153 ****
if (prologState.level >= groupSize) {
if (groupSize) {
! groupConnector = REALLOC(groupConnector, groupSize *= 2);
! if (dtd.scaffIndex)
! dtd.scaffIndex = REALLOC(dtd.scaffIndex, groupSize * sizeof(int));
}
! else
groupConnector = MALLOC(groupSize = 32);
! if (!groupConnector)
! return XML_ERROR_NO_MEMORY;
}
groupConnector[prologState.level] = 0;
--- 3146,3165 ----
if (prologState.level >= groupSize) {
if (groupSize) {
! char *temp = REALLOC(groupConnector, groupSize *= 2);
! if (temp == NULL)
! return XML_ERROR_NO_MEMORY;
! groupConnector = temp;
! if (dtd.scaffIndex) {
! int *temp = REALLOC(dtd.scaffIndex, groupSize * sizeof(int));
! if (temp == NULL)
! return XML_ERROR_NO_MEMORY;
! dtd.scaffIndex = temp;
! }
}
! else {
groupConnector = MALLOC(groupSize = 32);
! if (!groupConnector)
! return XML_ERROR_NO_MEMORY;
! }
}
groupConnector[prologState.level] = 0;
***************
*** 3831,3844 ****
type->allocDefaultAtts = 8;
type->defaultAtts = MALLOC(type->allocDefaultAtts
! * sizeof(DEFAULT_ATTRIBUTE));
}
else {
! type->allocDefaultAtts *= 2;
! type->defaultAtts = REALLOC(type->defaultAtts,
! (type->allocDefaultAtts
! * sizeof(DEFAULT_ATTRIBUTE)));
}
- if (!type->defaultAtts)
- return 0;
}
att = type->defaultAtts + type->nDefaultAtts;
--- 3843,3859 ----
type->allocDefaultAtts = 8;
type->defaultAtts = MALLOC(type->allocDefaultAtts
! * sizeof(DEFAULT_ATTRIBUTE));
! if (!type->defaultAtts)
! return 0;
}
else {
! DEFAULT_ATTRIBUTE *temp;
! int count = type->allocDefaultAtts * 2;
! temp = REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE)));
! if (temp == NULL)
! return 0;
! type->allocDefaultAtts = count;
! type->defaultAtts = temp;
}
}
att = type->defaultAtts + type->nDefaultAtts;
***************
*** 4231,4236 ****
newE->defaultAtts = (DEFAULT_ATTRIBUTE *)
MALLOC(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
! if (!newE->defaultAtts)
return 0;
}
if (oldE->idAtt)
--- 4246,4253 ----
newE->defaultAtts = (DEFAULT_ATTRIBUTE *)
MALLOC(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
! if (!newE->defaultAtts) {
! FREE(newE);
return 0;
+ }
}
if (oldE->idAtt)
***************
*** 4661,4676 ****
if (dtd.scaffCount >= dtd.scaffSize) {
if (dtd.scaffold) {
dtd.scaffSize *= 2;
- dtd.scaffold = (CONTENT_SCAFFOLD *)
- REALLOC(dtd.scaffold, dtd.scaffSize * sizeof(CONTENT_SCAFFOLD));
}
else {
dtd.scaffSize = 32;
- dtd.scaffold = (CONTENT_SCAFFOLD *)
- MALLOC(dtd.scaffSize * sizeof(CONTENT_SCAFFOLD));
}
! if (! dtd.scaffold)
! return -1;
}
next = dtd.scaffCount++;
--- 4678,4696 ----
if (dtd.scaffCount >= dtd.scaffSize) {
+ CONTENT_SCAFFOLD *temp;
if (dtd.scaffold) {
+ temp = (CONTENT_SCAFFOLD *)
+ REALLOC(dtd.scaffold, dtd.scaffSize * 2 * sizeof(CONTENT_SCAFFOLD));
+ if (temp == NULL)
+ return -1;
dtd.scaffSize *= 2;
}
else {
+ temp = MALLOC(dtd.scaffSize * sizeof(CONTENT_SCAFFOLD));
+ if (temp == NULL)
+ return -1;
dtd.scaffSize = 32;
}
! dtd.scaffold = temp;
}
next = dtd.scaffCount++;