Skip to content

Various memory management issues #24

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
artomal opened this issue Jun 3, 2020 · 5 comments
Closed

Various memory management issues #24

artomal opened this issue Jun 3, 2020 · 5 comments

Comments

@artomal
Copy link

artomal commented Jun 3, 2020

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?

@kou kou closed this as completed in 0357bc8 Jun 6, 2020
@kou
Copy link
Member

kou commented Jun 6, 2020

Thanks for your report.
I've fixed it.

@artomal
Copy link
Author

artomal commented Jun 8, 2020

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

@artomal
Copy link
Author

artomal commented Jun 8, 2020

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

kou added a commit that referenced this issue Jun 8, 2020
GitHub: fix GH-24

Reported by Arturas M. Thanks!!!
@kou
Copy link
Member

kou commented Jun 8, 2020

Could you try master?

@artomal
Copy link
Author

artomal commented Jun 9, 2020

It seems now it is fixed, thanks @kou !

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants