Skip to content

Commit a7fa224

Browse files
committed
Fix potential gc bug
1 parent fe9f7cd commit a7fa224

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

ext/libxml/ruby_xml_writer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ static VALUE rxml_writer_doc(VALUE klass)
196196
{
197197
xmlDocPtr doc;
198198
rxml_writer_object* rwo;
199+
VALUE output, result;
199200

200201
rwo = ALLOC(rxml_writer_object);
201202
rwo->buffer = NULL;
@@ -207,9 +208,12 @@ static VALUE rxml_writer_doc(VALUE klass)
207208
{
208209
rxml_raise(xmlGetLastError());
209210
}
210-
rwo->output = rxml_document_wrap(doc);
211+
output = rxml_document_wrap(doc);
212+
rwo->output = output;
211213

212-
return rxml_writer_wrap(rwo);
214+
result = rxml_writer_wrap(rwo);
215+
RB_GC_GUARD(output);
216+
return result;
213217
}
214218

215219
/* ===== public instance methods ===== */

0 commit comments

Comments
 (0)