File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -100,13 +100,14 @@ memsize_node(const xmlNodePtr node)
100100{
101101 /* note we don't count namespace definitions, just going for a good-enough number here */
102102 xmlNodePtr child ;
103+ xmlAttrPtr property ;
103104 size_t memsize = 0 ;
104105
105106 memsize += xmlStrlen (node -> name );
106107
107108 if (node -> type == XML_ELEMENT_NODE ) {
108- for (child = ( xmlNodePtr ) node -> properties ; child ; child = child -> next ) {
109- memsize += sizeof (xmlAttr ) + memsize_node (child );
109+ for (property = node -> properties ; property ; property = property -> next ) {
110+ memsize += sizeof (xmlAttr ) + memsize_node (( xmlNodePtr ) property );
110111 }
111112 }
112113 if (node -> type == XML_TEXT_NODE ) {
Original file line number Diff line number Diff line change @@ -313,6 +313,21 @@ def test_object_space_memsize_of
313313 assert ( bigger_name_size > base_size , "longer tags should increase memsize" )
314314 end
315315
316+ def test_object_space_memsize_with_dtd
317+ # https://github.com/sparklemotion/nokogiri/issues/2923
318+ require "objspace"
319+ skip ( "memsize_of not defined" ) unless ObjectSpace . respond_to? ( :memsize_of )
320+
321+ doc = Nokogiri ::XML ( <<~XML )
322+ <?xml version="1.0"?>
323+ <!DOCTYPE staff PUBLIC "staff.dtd" [
324+ <!ATTLIST payment type CDATA "check">
325+ ]>
326+ <staff></staff>
327+ XML
328+ ObjectSpace . memsize_of ( doc ) # assert_does_not_crash
329+ end
330+
316331 module MemInfo
317332 # from https://stackoverflow.com/questions/7220896/get-current-ruby-process-memory-usage
318333 # this is only going to work on linux
You can’t perform that action at this time.
0 commit comments