Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle xmlNs memory in xpath query results #1362

Closed
wants to merge 7 commits into from

Conversation

flavorjones
Copy link
Member

This patch addresses #1155

This patch introduces a bifurcation in how Namespace objects are managed; Namespace objects wrapped around xmlNs structs from an xpath query now have their own Ruby object lifecycle and are GCed independently from their original document.

See commits and comments in xml_node_set.c and xml_namespace.c for more details.

Shout out to @akshaysawant who helped diagnose the underlying issue.

Also note that this is clean under valgrind, and doesn't leak memory related to namespace xpath queries.

(This replaces #1360 and is rebased on a green commit.)

to stop freeing the namespace nodes when the NodeSet is GCed.

Related to #1155
to remove nokogiriNodeSetTuple which is no longer necessary

Related to #1155
This allows us to move repeated NULL checks out of callers.
introduce Check_Node_Set_Node_Type to replace repeated logic.
previously we had one code path (in #minus) that might try to free xmlNs
structs in the xmlNodeset.
this commit introduces a bifurcation in how Namespace objects are
managed; Namespace objects wrapped around xmlNs structs from an xpath
query now have their own Ruby object lifecycle and are GCed
independently from their original document.

See comments in xml_node_set.c and xml_namespace.c for more details.

Related to #1155
Data_Get_Struct(self, xmlNodeSet, node_set);
Data_Get_Struct(rb_node, xmlNode, node);

if (xmlXPathNodeSetContains(node_set, node)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this condition is unnecessary now, since xpath_node_set_del() does the same check internally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the return value changes, and so we need to know whether the object is in the node set or not.

We could have xpath_node_set_del return a boolean (found or not-found), but honestly I'll take the performance hit in exchange for more readable code at this point, given how complicated namespace handling is.

It's rare that namespaces are returned in xpath queries anyway, and so I'd prefer to leave it as-is.

@larskanis
Copy link
Member

Great work @flavorjones ! Looks like a correct solution to the GC issue. For sure much better than the previous way per st_table .

@flavorjones
Copy link
Member Author

Merged manually (with conflicts).

@flavorjones flavorjones deleted the flavorjones-1155-namespace-gc branch December 17, 2015 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants