[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua reference re-use
- From: Tim Hill <drtimhill@...>
- Date: Thu, 30 Jul 2015 12:08:48 -0700
> On Jul 30, 2015, at 3:46 AM, Chris Jones <firstname.lastname@example.org> wrote:
> 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.
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!).