[Expat-discuss] Re: Expat - terminating the parser
Sun Nov 24 13:54:45 2002
I have cc'ed this to the list - since others may have
something to say on that topic too.
> Thanks for your answer.
> I'm using Expat from C++. If I throw an exception from a
> callback, could it have any "undesirable" side effects
> (e.g., memory leaks, undefined parser status)? In other
> words, is Expat designed in a way that the user may safely
> throw exceptions from handlers?
I know the Expat code to a degree, and as far as I can tell,
there are no situations where heap memory is allocated
with only local variables referencing it before a handler
is called. Therefore - IMO - calling XML_ParserFree
should always work properly even when terminating
through an exception. However, I have not studied every
single handler call from that angle.
I have tested this with Delphi (not C++) and there did not
appear to be memory leaks because of that.
There is one situation when an element declaration is reported,
where the content model passed to the handler has to be freed
by the handler. In that case you have to catch the exception in
the handler, free the content model, and then re-throw the exception.
More information about the Expat-discuss