File tree 2 files changed +18
-2
lines changed
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)
100
100
{
101
101
/* note we don't count namespace definitions, just going for a good-enough number here */
102
102
xmlNodePtr child ;
103
+ xmlAttrPtr property ;
103
104
size_t memsize = 0 ;
104
105
105
106
memsize += xmlStrlen (node -> name );
106
107
107
108
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 );
110
111
}
111
112
}
112
113
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
313
313
assert ( bigger_name_size > base_size , "longer tags should increase memsize" )
314
314
end
315
315
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
+
316
331
module MemInfo
317
332
# from https://stackoverflow.com/questions/7220896/get-current-ruby-process-memory-usage
318
333
# this is only going to work on linux
You can’t perform that action at this time.
0 commit comments