Skip to content

Memory leak on added object #8

@tempelmann

Description

@tempelmann

See this line in LuaTests.m:

result = [ctx call:"setPublicPr" with:@[ @5 ] error:&error];

It invokes the following Lua code:

function setPublicPr (v)
  ex.publicString = v
  print(v)
  return v
end

The Lua engine will throw an error in the line ex.publicString = v because of incompatible types.

The problem is that this will add a reference to the ex object, which will result in a leak.

I've tried to figure out why this happens, and which part of the code causes the leak but wasn't successfuly. I found that it's related to throwing an error in the code outlined in issue #9, though. If no error is raised, then there's no leak. Since the Lua code uses setjmp() to exit from deep code throwing an error, there is no unwinding of intermediate states happening, though. I suspect that some intermediate caller between the LUAI_TRY in luaD_rawrunprotected and the call of lua_error(L) in luaWrapperNewIndex needs to do some cleanup.

If ARC is disabled and the few objects are instead manually retained and released, the issue does not occur, even if the above error is thrown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions