Skip to content

Commit

Permalink
add a test for double free detection
Browse files Browse the repository at this point in the history
  • Loading branch information
defunctzombie committed Jan 6, 2013
1 parent ceb6f23 commit f652298
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/ref_integrity.js
Expand Up @@ -25,3 +25,26 @@ module.exports.references = function(assert) {
assert.equal("child", nodes[1].name()); assert.equal("child", nodes[1].name());
assert.done(); assert.done();
}; };

// test that double-freeing XmlNode's doesn't cause a segfault
module.exports.double_free = function(assert) {
var children = null;

// stick this portion of code into a self-executing function so
// its internal variables can be garbage collected
(function(){
var html = '<html><body><div><span></span></div></body></html>';
var doc = libxml.parseHtml(html);

doc.find('//div').forEach(function(tag){
// provide a reference to childNodes so they are exposed as XmlNodes
// and therefore subject to V8's garbage collection
children = tag.childNodes();
tag.remove();
});
})();

global.gc();
assert.ok(children[0].attrs());
assert.done();
};

0 comments on commit f652298

Please sign in to comment.