[xsd-users] cxx-parser: Not all attributes in the XML namespace are typemapped.

Boris Kolpackov boris at codesynthesis.com
Mon Jan 21 03:16:57 EST 2008


Hi Jeroen,

Jeroen N. Witmond [Bahco] <jnw at xs4all.nl> writes:

> > This is a bug and it is now fixed for 3.1.0.
>
> I assume you mean it is fixed afer 3.1.0.b1.

Right, the fix will be in the 3.1.0 final release.


> I've fixed this bug by making the following change in the generated code:
> --- lax.cxx	2008-01-20 13:14:32.000000000 +0100
> +++ lax.cpp	2008-01-20 16:01:42.000000000 +0100
> @@ -400,18 +400,15 @@
>      ::xsd::cxx::xml::dom::auto_ptr< ::xercesc::DOMDocument > d (
>        ::xsd::cxx::xml::dom::parse< char > (u, h, p, f));
>
>      h.throw_if_failed< ::xsd::cxx::tree::parsing< char > > ();
>
>      ::std::auto_ptr< ::metadox::foo_type > r (
>        ::metadox::foo (
> -        d.get (), f | ::xml_schema::flags::own_dom, p));
> -
> -    if (f & ::xml_schema::flags::keep_dom)
> -      d.release ();
> +        d.release (), f | ::xml_schema::flags::own_dom, p));
>
>      return r;
>    }
>
>    ::std::auto_ptr< ::metadox::foo_type >
>    foo (const ::std::string& u,
>         ::xml_schema::error_handler& h,

The problem with this fix is that it will result in a memory leak
if an exception is thrown from metadox::foo before the constructor
for the root type is called. This will happen, for example, if the
root element in the document does not match that expected by the
parsing function.

In normal circumstances this kind of problem is address by passing
an automatic pointer (e.g., dom::auto_ptr) which is reset at the
point where the new object assumes ownership of the resource. In
our case, we pass a root element to the constructor and depending
on the flag (keep_dom), the constructor also assumes ownership of
the document. An ugly, but workable solution would be to pass a
pointer to the dom::auto_ptr as user data attached to the document.
This way the root type constructor can reset auto_ptr when it assumes
ownership. Let me know if you have a better idea ;-).

Boris




More information about the xsd-users mailing list