Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Oct 2010 15:27:45 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r213451 - head/lib/libgeom
Message-ID:  <201010051527.o95FRjAN060833@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Tue Oct  5 15:27:44 2010
New Revision: 213451
URL: http://svn.freebsd.org/changeset/base/213451

Log:
  Handle null return from XML_ParserCreate and fix a few memory leaks on
  error conditions.
  
  Submitted by:	Mark Johnston <mjohnston at sandvine dot com>
  MFC after:	2 weeks

Modified:
  head/lib/libgeom/geom_xml2tree.c

Modified: head/lib/libgeom/geom_xml2tree.c
==============================================================================
--- head/lib/libgeom/geom_xml2tree.c	Tue Oct  5 09:20:46 2010	(r213450)
+++ head/lib/libgeom/geom_xml2tree.c	Tue Oct  5 15:27:44 2010	(r213451)
@@ -339,21 +339,27 @@ geom_xml2tree(struct gmesh *gmp, char *p
 	memset(gmp, 0, sizeof *gmp);
 	LIST_INIT(&gmp->lg_class);
 	parser = XML_ParserCreate(NULL);
+	if (parser == NULL)
+		return (ENOMEM);
 	mt = calloc(1, sizeof *mt);
-	if (mt == NULL)
+	if (mt == NULL) {
+		XML_ParserFree(parser);
 		return (ENOMEM);
+	}
 	mt->mesh = gmp;
 	XML_SetUserData(parser, mt);
 	XML_SetElementHandler(parser, StartElement, EndElement);
 	XML_SetCharacterDataHandler(parser, CharData);
 	i = XML_Parse(parser, p, strlen(p), 1);
-	if (i != 1)
-		return (-1);
 	XML_ParserFree(parser);
+	if (i != 1) {
+		free(mt);
+		return (-1);
+	}
 	gmp->lg_ident = calloc(sizeof *gmp->lg_ident, mt->nident + 1);
+	free(mt);
 	if (gmp->lg_ident == NULL)
 		return (ENOMEM);
-	free(mt);
 	i = 0;
 	/* Collect all identifiers */
 	LIST_FOREACH(cl, &gmp->lg_class, lg_class) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201010051527.o95FRjAN060833>