Skip to content

Various memory management issues #24

@artomal

Description

@artomal

Hi there,

I've been testing this library and playing with a different operations and noticed a problem with memory management once you start playing with elements and combining them together. I used the script below to reproduce the issue:

local xmlua = require("xmlua")

local function add_child(parent, child)
  return parent:add_child(child)
end

local function create_element(name, attributes)
  local elm = xmlua.XML.build({ name }):root()

  if attributes then
    for att_name, val in pairs(attributes) do
      elm:set_attribute(att_name, val)
    end
  end

  return elm:unlink()
end

for i=1,5000 do
  local a = create_element("a", {
    ["a1"] = "a1-test",
    ["a2"]  = "a2-test"
  })

  local b = create_element("b", {
    ["b1"] = "b1-test",
    ["b2"]  = "b2-test"
  })

  add_child(a, b)
  print("[i] " .. i .. " " .. a:to_xml())
end

The script doesn't even finish and errors at 2xx, 3xx iteration I get a different memory related error messages for instance:

malloc_consolidate(): invalid chunk size

or:

free(): invalid pointer

Any ideas what might be happening? Maybe I use illegal API operations which introduce these type of problems?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions