lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> On Jul 30, 2015, at 3:46 AM, Chris Jones <cmsj@tenshu.net> wrote:
> 
> Hey
> 
> If one does luaL_ref(), luaL_unref() and luaL_ref() again, there's a fair chance that the same reference number will be handed out twice.
> 
> I'm wondering if it would be better if the references handed out by luaL_ref() were only ever given out once? I think it would help track down use-after-free type bugs, where right now you get either confusing data of the wrong type, or take incorrect action on data that happens to be the right type.
> 
> Clearly this is only an issue in code that has bugs, but we know that all code has bugs, and I think finding them would be easier if a lua_rawgeti() on a reference that had been released, would be able to return a clear "NO YOU ARE DOING SOMETHING WRONG" error.
> 
> Thoughts?
> 
> -- 
> Cheers,
> 
> Chris

If you think about it, such a “generator” is trivial; it’s just an integer variable you increment every time you get a “reference”. Voila! References that are never reused (until you get through all 2^63 or so … good luck doing that!).

—Tim