libxml-raku / LibXML-raku

Raku bindings to the libxml2 native library
Artistic License 2.0
11 stars 4 forks source link

Memory leak in .Str on a LibXML::Node #77

Closed jnthn closed 2 years ago

jnthn commented 2 years ago

Doing Str on a node bottoms out, best I can tell, in anyNode's Str function in LibXML::Raw, which uses this native function:

    method xml6_node_to_str(int32 $opts --> Str) is native($BIND-XML2) {*}

The called function allocates and returns a buffer, assuming the caller will free it. However, NativeCall assumes that the memory returned and converted to a Str should not be freed as part of the process. I've been able to work around this by using .Blob instead (which it turns out is more efficient in my use case, since I was only encoding the Str anyway). Probably the best bet is for .Str to delegate to .Blob and then .decode the result.

dwarring commented 2 years ago

Fixed in LibXML 0.7.8. This release also fixes several other memory leaks covered in #78.

dwarring commented 2 years ago

All fixes were related to malloced strings not being freed by the Raku bindings.

zaucker commented 2 years ago

Seems this improved the leaking in my use case (reports with Spreadsheet:XLSX) quite a bit. Thanks for the fast reaction on Jonathan's report.