[libxml-devel] Memory leak with 0.9.6 and 0.9.7
Aaron Patterson
aaron.patterson at gmail.com
Wed Jan 7 19:36:10 EST 2009
2009/1/7 Charlie Savage <cfis at savagexi.com>:
> Hi Joseph,
>
>>> I'll see if I can put something together, we know it's in the
>>> to_solr_doc from acts_as_solr somewhere.
>>
>> Looks like the problem is in to_s on Node
>>
>> 10000.times do
>> node = XML::Node.new 'node'
>> node.to_s
>> end
>
> Nice work - that's a great test case.
>
> So if I I run this code:
>
> 10000000.times do
> node = XML::Node.new 'node'
> #node.to_s
> end
>
> I see no issues.
>
> Adding the .to_s does seem to cause a problem. Are you actually doing so
> many to_s calls in your code?
>
> Anyway, will have to look and see if there is anything obvious in the part
> of the bindings.
Looks like the xmlOutputBufferPtr never gets freed.
This might do the trick:
Index: ext/libxml/ruby_xml_node.c
===================================================================
--- ext/libxml/ruby_xml_node.c (revision 693)
+++ ext/libxml/ruby_xml_node.c (working copy)
@@ -570,10 +570,16 @@
xmlNodeDumpOutput(output, xnode->doc, xnode, level, indent, encoding);
xmlOutputBufferFlush(output);
+ VALUE string = Qnil;
+
if (output->conv)
- return rb_str_new2((const char*) output->conv->content);
+ string = rb_str_new2((const char*) output->conv->content);
else
- return rb_str_new2((const char*) output->buffer->content);
+ string = rb_str_new2((const char*) output->buffer->content);
+
+ xmlOutputBufferClose(output);
+
+ return string;
}
--
Aaron Patterson
http://tenderlovemaking.com/
More information about the libxml-devel
mailing list