Skip to content
This repository
Browse code

Merge branch 'master' of github.com:polotek/libxmljs

  • Loading branch information...
commit fca49f121b77ee43dff850f9436ba452506f621f 2 parents d4cbbc9 + f652298
Nick Campbell ncb000gt authored

Showing 1 changed file with 23 additions and 0 deletions. Show diff stats Hide diff stats

  1. +23 0 test/ref_integrity.js
23 test/ref_integrity.js
@@ -25,3 +25,26 @@ module.exports.references = function(assert) {
25 25 assert.equal("child", nodes[1].name());
26 26 assert.done();
27 27 };
  28 +
  29 +// test that double-freeing XmlNode's doesn't cause a segfault
  30 +module.exports.double_free = function(assert) {
  31 + var children = null;
  32 +
  33 + // stick this portion of code into a self-executing function so
  34 + // its internal variables can be garbage collected
  35 + (function(){
  36 + var html = '<html><body><div><span></span></div></body></html>';
  37 + var doc = libxml.parseHtml(html);
  38 +
  39 + doc.find('//div').forEach(function(tag){
  40 + // provide a reference to childNodes so they are exposed as XmlNodes
  41 + // and therefore subject to V8's garbage collection
  42 + children = tag.childNodes();
  43 + tag.remove();
  44 + });
  45 + })();
  46 +
  47 + global.gc();
  48 + assert.ok(children[0].attrs());
  49 + assert.done();
  50 +};

0 comments on commit fca49f1

Please sign in to comment.
Something went wrong with that request. Please try again.