[lxml-dev] thread-related crash when using xslt

Martijn Faassen faassen at startifact.com
Fri Feb 27 16:50:08 CET 2009


Hey Stefan,

On Fri, Feb 27, 2009 at 12:41 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Martijn Faassen wrote:
>> Attached is a small tarball that demonstrates code that crashes when the
>> code is run in a thread but doesn't crash when it is run stand-alone. I
>> isolated the specific XSLT + XML combination that seems to trigger this
>> crash. I suspect it has to do with passing an XSLT object to a thread.
>
> Ok, this is plain evil. What you do here is this:
>
>     ...
>     <tr class="odd">
>        <xsl:attribute name="class">top-row</xsl:attribute>
>     ...

I didn't do it, or if I did do it it was years ago and I don't remember! :)

[snip]
> So the first "class" attribute name comes from the stylesheet dict and gets
> stored in the result document that inherits the thread dict of the input
> document. When it is overwritten and deleted, it is looked up in the thread
> dict, is not found there, and thus free()-ed, although it continues to
> 'live' in the stylesheet dict.

Ugh!

FYI I've worked around the problem in the original application (Silva)
by having a thread-local XSLT stylesheet for each thread now. This
seems to resolve the actual crash in the application and has a minimal
performance impact as far as I can see. Given Silva's history with
thread-related issues with XSLT such a general workaround might be the
best way forward, though it does mean you'll see less thread related
bug reports coming from that direction. :)

I see however that you thought up a fix in the reply, which is good
news for people coming after me. :)

Regards,

Martijn


More information about the lxml-dev mailing list