[xsd-users] cxx-tree: Problems with keep_dom and throwing custom type constructors

Jeroen N. Witmond [Bahco] jnw at xs4all.nl
Tue Jan 22 12:19:49 EST 2008


Hi Boris,

[This thread started as "Re: [xsd-users] cxx-parser: Not all attributes in
the XML namespace are typemapped." The previous message in this thread is
http://codesynthesis.com/pipermail/xsd-users/2008-January/001444.html ]

Boris Kolpackov <boris at codesynthesis.com> wrote:

> Jeroen N. Witmond [Bahco] <jnw at xs4all.nl> writes:
>> I've fixed this bug by making the following change in the generated
>> code:
[snip]

> 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.

Yep, my unittest did not include that scenario. It does now, and as
expected it shows the leak.

And I shouldn't have called it a fix, because it is just an incomplete
hack in generated code. But it did allow me to verify that the problem is
not in my code. :)

> 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.

By normal circumstances I assume you mean you do not want to change the API.

> 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 ;-).

You're right, it's ugly, it's workable, and, if my assumption above is
correct, I don't have any better ideas. :)

Jeroen.





More information about the xsd-users mailing list