libxml++ r191 - in trunk: . libxml++ libxml++/validators
- From: arminb svn gnome org
- To: svn-commits-list gnome org
- Subject: libxml++ r191 - in trunk: . libxml++ libxml++/validators
- Date: Mon, 22 Dec 2008 11:34:04 +0000 (UTC)
Author: arminb
Date: Mon Dec 22 11:34:04 2008
New Revision: 191
URL: http://svn.gnome.org/viewvc/libxml++?rev=191&view=rev
Log:
2008-12-20 Armin Burgmeier <armin openismus com>
* libxml++/schema.cc (set_document): Set embedded_doc_ according to
the embed parameter instead of always setting it to false, so that we
actually release the document in release_underlying().
(release_underlying): Free the schema in all cases, also when the
document was not embedded, to avoid a memory leak.
* libxml++/validators/schemavalidator.cc (parse_file, parse_memory,
parse_document): Make sure not to leak the xmlSchemaParserCtxtPtr in
case of an exception. Bug #563321, Arjan Franzen.
Modified:
trunk/ChangeLog
trunk/libxml++/schema.cc
trunk/libxml++/validators/schemavalidator.cc
Modified: trunk/libxml++/schema.cc
==============================================================================
--- trunk/libxml++/schema.cc (original)
+++ trunk/libxml++/schema.cc Mon Dec 22 11:34:04 2008
@@ -41,7 +41,7 @@
if ( !impl_ )
throw parse_error("Schema could not be parsed");
impl_->_private = this;
- embedded_doc_ = false;
+ embedded_doc_ = embed;
xmlSchemaFreeParserCtxt( context );
}
@@ -65,12 +65,13 @@
if(embedded_doc_ && impl_ && impl_->doc->_private)
{
delete (Document*) impl_->doc->_private;
+ embedded_doc_ = false;
+ }
- if(impl_)
- xmlSchemaFree(impl_);
-
+ if(impl_)
+ {
+ xmlSchemaFree(impl_);
impl_ = 0;
- embedded_doc_ = false;
}
}
Modified: trunk/libxml++/validators/schemavalidator.cc
==============================================================================
--- trunk/libxml++/validators/schemavalidator.cc (original)
+++ trunk/libxml++/validators/schemavalidator.cc Mon Dec 22 11:34:04 2008
@@ -14,6 +14,22 @@
#include <sstream>
#include <iostream>
+namespace
+{
+ // This class simply holds a xmlSchemaParserCtxtPtr and releases it on
+ // destruction. This way, we make sure we don't leak it in either case,
+ // even when an exception is thrown.
+ class XmlSchemaParserContextHolder
+ {
+ public:
+ XmlSchemaParserContextHolder(xmlSchemaParserCtxtPtr ptr): ptr_(ptr) {}
+ ~XmlSchemaParserContextHolder() { xmlSchemaFreeParserCtxt(ptr_); }
+
+ private:
+ xmlSchemaParserCtxtPtr ptr_;
+ };
+}
+
namespace xmlpp
{
@@ -70,22 +86,22 @@
void SchemaValidator::parse_file(const Glib::ustring& filename)
{
xmlSchemaParserCtxtPtr ctx = xmlSchemaNewParserCtxt( filename.c_str() );
+ XmlSchemaParserContextHolder holder(ctx);
parse_context( ctx );
- xmlSchemaFreeParserCtxt( ctx );
}
void SchemaValidator::parse_memory(const Glib::ustring& contents)
{
xmlSchemaParserCtxtPtr ctx = xmlSchemaNewMemParserCtxt( contents.c_str(), contents.bytes() );
+ XmlSchemaParserContextHolder holder(ctx);
parse_context( ctx );
- xmlSchemaFreeParserCtxt( ctx );
}
void SchemaValidator::parse_document(Document& document)
{
xmlSchemaParserCtxtPtr ctx = xmlSchemaNewDocParserCtxt( document.cobj() );
+ XmlSchemaParserContextHolder holder(ctx);
parse_context( ctx );
- xmlSchemaFreeParserCtxt( ctx );
}
void SchemaValidator::set_schema(Schema* schema)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]