@@ -124,11 +124,7 @@ function libxml2.htmlCtxtReadMemory(context, html, options)
124124 if document == ffi .NULL then
125125 return nil
126126 end
127- print_dbg (" htmlCtxtReadMemory: " , document )
128- return ffi .gc (document , function (p )
129- print_dbg (" xmlFreeDoc: " , p )
130- xml2 .xmlFreeNode (p )
131- end )
127+ return ffi .gc (document , xml2 .xmlFreeDoc )
132128end
133129jit .off (libxml2 .htmlCtxtReadMemory )
134130
@@ -137,7 +133,7 @@ function libxml2.htmlNewDoc(uri, externa_dtd)
137133 if document == ffi .NULL then
138134 return nil
139135 end
140- return ffi .gc (document , libxml2 .xmlFreeDoc )
136+ return ffi .gc (document , xml2 .xmlFreeDoc )
141137end
142138
143139function libxml2 .xmlNewParserCtxt ()
@@ -214,10 +210,7 @@ function libxml2.xmlCtxtReadMemory(context, xml, options)
214210 return nil
215211 end
216212 print_dbg (" xmlCtxtReadMemory: " , document , " , ctx=" , context )
217- return ffi .gc (document , function (p )
218- print_dbg (" xmlFreeDoc: " , p , " , ctx=" , context )
219- xml2 .xmlFreeDoc (p )
220- end )
213+ return ffi .gc (document , libxml2 .xmlFreeDoc )
221214
222215end
223216jit .off (libxml2 .xmlCtxtReadMemory )
@@ -230,7 +223,10 @@ function libxml2.xmlParseChunk(context, chunk, is_terminated)
230223 end
231224end
232225
233- libxml2 .xmlFreeDoc = xml2 .xmlFreeDoc
226+ function libxml2 .xmlFreeDoc (document )
227+ print_dbg (" xmlFreeDoc: " , document )
228+ xml2 .xmlFreeDoc (document )
229+ end
234230
235231function libxml2 .xmlDocGetRootElement (document )
236232 local root = xml2 .xmlDocGetRootElement (document )
@@ -311,10 +307,7 @@ function libxml2.xmlNewDoc(xml_version)
311307 return nil
312308 end
313309 print_dbg (" xmlNewDoc: " , document )
314- return ffi .gc (document , function (p )
315- print_dbg (" xmlFreeDoc: " , p )
316- xml2 .xmlFreeDoc (p )
317- end )
310+ return ffi .gc (document , libxml2 .xmlFreeDoc )
318311end
319312
320313function libxml2 .xmlDocSetRootElement (document , root )
@@ -605,6 +598,7 @@ function libxml2.xmlDocCopyNode(node, doc)
605598end
606599
607600function libxml2 .xmlFreeNode (node )
601+ assert (node .parent == ffi .NULL , " node linked" )
608602 print_dbg (" xmlFreeNode: " , node , " , doc=" , node .doc )
609603 xml2 .xmlFreeNode (node )
610604end
0 commit comments