Skip to content

Various memory management issues #24

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?

Activity

  1. kou commented on Jun 6, 2020

    @kou
    Member

    Thanks for your report.
    I've fixed it.

  2. artomal commented on Jun 8, 2020

    @artomal
    Author

    Hi @kou , thanks for a quick response, it seems that issue still persists and it is only partially resolved, if you would run this script a couple of times it sometimes finishes after 5k iterations and sometimes it exits earlier after ~5xx iterations without any error but if you look at exit code with echo $? I see it is 11

    ...
    <b b2="b2-test" b1="b1-test"/>
    </a>
    [i] 476 <a a1="a1-test" a2="a2-test">
      <b b2="b2-test" b1="b1-test"/>
    </a>
    [i] 477 <a a1="a1-test" a2="a2-test">
      <b b2="b2-test" b1="b1-test"/>
    </a>
    [i] 478 <a a1="a1-test" a2="a2-test">
      <b b2="b2-test" b1="b1-test"/>
    </a>
    [i] 479 <a a1="a1-test" a2="a2-test">
      <b b2="b2-test" b1="b1-test"/>
    </a>
    $ echo $?
    $ 11
    
  3. artomal commented on Jun 8, 2020

    @artomal
    Author

    I think the problem happens when you have two unlinked elements and combine them together using add_child().

  4. added a commit that references this issue on Jun 8, 2020
    dbce69a
  5. kou commented on Jun 8, 2020

    @kou
    Member

    Could you try master?

  6. artomal commented on Jun 9, 2020

    @artomal
    Author

    It seems now it is fixed, thanks @kou !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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