Skip to content

Commit 613a11c

Browse files
committed
Try to fix crash on MacOS
1 parent 9234559 commit 613a11c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ext/libxml/ruby_xml_xpath_context.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ static VALUE rxml_xpath_context_initialize(VALUE self, VALUE document)
9090
if (wrapper == NULL)
9191
{
9292
wrapper = ALLOC(rxml_xpath_context);
93+
wrapper->xctxt = NULL;
94+
wrapper->document = document;
9395
RTYPEDDATA_DATA(self) = wrapper;
9496
}
9597
else if (wrapper->xctxt)
9698
{
9799
xmlXPathFreeContext(wrapper->xctxt);
98100
}
99101

100-
wrapper->document = document;
101102
wrapper->xctxt = xmlXPathNewContext(xdoc);
102103

103104
return self;

ext/libxml/ruby_xml_xpath_object.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static const rb_data_type_t rxml_xpath_object_data_type = {
7373
VALUE rxml_xpath_object_wrap(VALUE document, xmlDocPtr xdoc, xmlXPathObjectPtr xpop)
7474
{
7575
int i;
76+
VALUE result;
7677
rxml_xpath_object *rxpopp = ALLOC(rxml_xpath_object);
7778

7879
/* Make sure Ruby's GC can find the array in the stack */
@@ -106,7 +107,9 @@ VALUE rxml_xpath_object_wrap(VALUE document, xmlDocPtr xdoc, xmlXPathObjectPtr x
106107
}
107108

108109
rxpopp->nsnodes = nsnodes;
109-
return TypedData_Wrap_Struct(cXMLXPathObject, &rxml_xpath_object_data_type, rxpopp);
110+
result = TypedData_Wrap_Struct(cXMLXPathObject, &rxml_xpath_object_data_type, rxpopp);
111+
RB_GC_GUARD(nsnodes);
112+
return result;
110113
}
111114

112115
static VALUE rxml_xpath_object_tabref(xmlXPathObjectPtr xpop, int index)

0 commit comments

Comments
 (0)