aboutsummaryrefslogtreecommitdiff
path: root/lib/libgeom/geom_xml2tree.c
diff options
context:
space:
mode:
authorUlf Lilleengen <lulf@FreeBSD.org>2008-07-08 17:34:50 +0000
committerUlf Lilleengen <lulf@FreeBSD.org>2008-07-08 17:34:50 +0000
commit7b6942a110f1c489c295ac85be8737c2955a737a (patch)
tree5b3be73bdbe84255bd046a32bc817c208bfefb52 /lib/libgeom/geom_xml2tree.c
parent7b709f8ad4600dcc27d591c86d6bf094ef800f74 (diff)
- Simplify the procedure of retrieving XML-data from the kernel.
- Fix a number of potential memory leaks in libgeom related to doing realloc without freeing old pointer if things go wrong. - Fix a number of places in libgeom where malloc and calloc return values were not checked. - Check malloc return value and provide sufficient warning messages when XML parsing fails. PR: kern/83464 Submitted by: Dan Lukes <dan - at - obluda.cz> Approved by: kib (mentor)
Notes
Notes: svn path=/head/; revision=180369
Diffstat (limited to 'lib/libgeom/geom_xml2tree.c')
-rw-r--r--lib/libgeom/geom_xml2tree.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/libgeom/geom_xml2tree.c b/lib/libgeom/geom_xml2tree.c
index 7798f44544af..08fb394eefc4 100644
--- a/lib/libgeom/geom_xml2tree.c
+++ b/lib/libgeom/geom_xml2tree.c
@@ -84,6 +84,11 @@ StartElement(void *userData, const char *name, const char **attr)
}
if (!strcmp(name, "class") && mt->class == NULL) {
mt->class = calloc(1, sizeof *mt->class);
+ if (mt->class == NULL) {
+ warn("Cannot allocate memory during processing of '%s' "
+ "element", name);
+ return;
+ }
mt->class->lg_id = id;
LIST_INSERT_HEAD(&mt->mesh->lg_class, mt->class, lg_class);
LIST_INIT(&mt->class->lg_geom);
@@ -92,6 +97,11 @@ StartElement(void *userData, const char *name, const char **attr)
}
if (!strcmp(name, "geom") && mt->geom == NULL) {
mt->geom = calloc(1, sizeof *mt->geom);
+ if (mt->geom == NULL) {
+ warn("Cannot allocate memory during processing of '%s' "
+ "element", name);
+ return;
+ }
mt->geom->lg_id = id;
LIST_INSERT_HEAD(&mt->class->lg_geom, mt->geom, lg_geom);
LIST_INIT(&mt->geom->lg_provider);
@@ -105,6 +115,11 @@ StartElement(void *userData, const char *name, const char **attr)
}
if (!strcmp(name, "consumer") && mt->consumer == NULL) {
mt->consumer = calloc(1, sizeof *mt->consumer);
+ if (mt->consumer == NULL) {
+ warn("Cannot allocate memory during processing of '%s' "
+ "element", name);
+ return;
+ }
mt->consumer->lg_id = id;
LIST_INSERT_HEAD(&mt->geom->lg_consumer, mt->consumer,
lg_consumer);
@@ -121,6 +136,11 @@ StartElement(void *userData, const char *name, const char **attr)
}
if (!strcmp(name, "provider") && mt->provider == NULL) {
mt->provider = calloc(1, sizeof *mt->provider);
+ if (mt->provider == NULL) {
+ warn("Cannot allocate memory during processing of '%s' "
+ "element", name);
+ return;
+ }
mt->provider->lg_id = id;
LIST_INSERT_HEAD(&mt->geom->lg_provider, mt->provider,
lg_provider);
@@ -162,6 +182,11 @@ EndElement(void *userData, const char *name)
mt = userData;
sbuf_finish(mt->sbuf[mt->level]);
p = strdup(sbuf_data(mt->sbuf[mt->level]));
+ if (p == NULL) {
+ warn("Cannot allocate memory during processing of '%s' "
+ "element", name);
+ return;
+ }
sbuf_delete(mt->sbuf[mt->level]);
mt->sbuf[mt->level] = NULL;
mt->level--;
@@ -212,8 +237,18 @@ EndElement(void *userData, const char *name)
}
if (mt->config != NULL) {
- gc = calloc(sizeof *gc, 1);
+ gc = calloc(1, sizeof *gc);
+ if (gc == NULL) {
+ warn("Cannot allocate memory during processing of '%s' "
+ "element", name);
+ return;
+ }
gc->lg_name = strdup(name);
+ if (gc->lg_name == NULL) {
+ warn("Cannot allocate memory during processing of '%s' "
+ "element", name);
+ return;
+ }
gc->lg_val = p;
LIST_INSERT_HEAD(mt->config, gc, lg_config);
return;